Skip to content

Commit 70f74d3

Browse files
committed
Resolve ml-queries from directory
Previously, there was a bug where quick eval queries would crash when the eval snippet is in a library file. The problem was that the `codeql resolve queries` command fails when passed a library file. The fix is to avoid passing the library file at all. Instead, pass the directory. This is safe because the resolve queries command only needs to know which query pack the file is contained in. Passing in the parent directory is the same as passing in a file in this particular case.
1 parent ebad184 commit 70f74d3

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,8 @@ export class CodeQLCliServer implements Disposable {
606606
/** Resolves the ML models that should be available when evaluating a query. */
607607
async resolveMlModels(additionalPacks: string[], queryPath: string): Promise<MlModelsInfo> {
608608
const args = await this.cliConstraints.supportsPreciseResolveMlModels()
609-
? [...this.getAdditionalPacksArg(additionalPacks), queryPath]
609+
// use the dirname of the path so that we can handle query libraries
610+
? [...this.getAdditionalPacksArg(additionalPacks), path.dirname(queryPath)]
610611
: this.getAdditionalPacksArg(additionalPacks);
611612
return await this.runJsonCodeQlCliCommand<MlModelsInfo>(
612613
['resolve', 'ml-models'],

extensions/ql-vscode/src/run-queries.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,7 @@ export async function compileAndRunQueryAgainstDatabase(
789789
const metadata = await tryGetQueryMetadata(cliServer, qlProgram.queryPath);
790790

791791
let availableMlModels: cli.MlModelInfo[] = [];
792-
if (!initialInfo.queryPath.endsWith('.ql')) {
793-
void logger.log('Quick evaluation within a query library does not currently support using ML models. Continuing without any ML models.');
794-
} else if (!await cliServer.cliConstraints.supportsResolveMlModels()) {
792+
if (!await cliServer.cliConstraints.supportsResolveMlModels()) {
795793
void logger.log('Resolving ML models is unsupported by this version of the CLI. Running the query without any ML models.');
796794
} else {
797795
try {

0 commit comments

Comments
 (0)