From 90ec003386ed981c77c1252ecf63ac4ca3e91644 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Tue, 24 May 2022 17:24:46 -0700 Subject: [PATCH 1/2] Add new support for resolve ml-models The new support will be available in the next release of the CLI, most likely 2.9.3, This change requires the query to be run to be passed in to the call to resolve ml-models. --- extensions/ql-vscode/src/cli.ts | 17 +++++++++++++++-- extensions/ql-vscode/src/run-queries.ts | 14 +++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index 1819a456600..cf36b0422b3 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -604,10 +604,13 @@ export class CodeQLCliServer implements Disposable { } /** Resolves the ML models that should be available when evaluating a query. */ - async resolveMlModels(additionalPacks: string[]): Promise { + async resolveMlModels(additionalPacks: string[], queryPath: string): Promise { + const args = await this.cliConstraints.supportsPreciseResolveMlModels() + ? [...this.getAdditionalPacksArg(additionalPacks), queryPath] + : this.getAdditionalPacksArg(additionalPacks); return await this.runJsonCodeQlCliCommand( ['resolve', 'ml-models'], - this.getAdditionalPacksArg(additionalPacks), + args, 'Resolving ML models', false ); @@ -1264,6 +1267,12 @@ export class CliVersionConstraint { */ public static CLI_VERSION_WITH_RESOLVE_ML_MODELS = new SemVer('2.7.3'); + /** + * CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging. + */ + // TODO: This is not the right version yet + public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer('2.9.3'); + /** * CLI version where the `--old-eval-stats` option to the query server was introduced. */ @@ -1339,6 +1348,10 @@ export class CliVersionConstraint { return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS); } + async supportsPreciseResolveMlModels() { + return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS); + } + async supportsOldEvalStats() { return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS); } diff --git a/extensions/ql-vscode/src/run-queries.ts b/extensions/ql-vscode/src/run-queries.ts index 797d05e553c..717830361b2 100644 --- a/extensions/ql-vscode/src/run-queries.ts +++ b/extensions/ql-vscode/src/run-queries.ts @@ -174,7 +174,7 @@ export class QueryEvaluationInfo { db: dataset, logPath: this.evalLogPath, }); - + } const params: messages.EvaluateQueriesParams = { db: dataset, @@ -204,7 +204,7 @@ export class QueryEvaluationInfo { queryInfo.evalLogSummaryLocation = this.evalLogSummaryPath; fs.readFile(this.evalLogEndSummaryPath, (err, buffer) => { if (err) { - throw new Error(`Could not read structured evaluator log end of summary file at ${this.evalLogEndSummaryPath}.`); + throw new Error(`Could not read structured evaluator log end of summary file at ${this.evalLogEndSummaryPath}.`); } void qs.logger.log(' --- Evaluator Log Summary --- ', { additionalLogLocation: this.logPath }); void qs.logger.log(buffer.toString(), { additionalLogLocation: this.logPath }); @@ -334,7 +334,7 @@ export class QueryEvaluationInfo { /** * Holds if this query already has a completed structured evaluator log */ - async hasEvalLog(): Promise { + async hasEvalLog(): Promise { return fs.pathExists(this.evalLogPath); } @@ -755,8 +755,12 @@ export async function compileAndRunQueryAgainstDatabase( let availableMlModels: cli.MlModelInfo[] = []; if (await cliServer.cliConstraints.supportsResolveMlModels()) { try { - availableMlModels = (await cliServer.resolveMlModels(diskWorkspaceFolders)).models; - void logger.log(`Found available ML models at the following paths: ${availableMlModels.map(x => `'${x.path}'`).join(', ')}.`); + availableMlModels = (await cliServer.resolveMlModels(diskWorkspaceFolders, initialInfo.queryPath)).models; + if (availableMlModels.length) { + void logger.log(`Found available ML models at the following paths: ${availableMlModels.map(x => `'${x.path}'`).join(', ')}.`); + } else { + void logger.log('Did not find any available ML models.'); + } } catch (e) { const message = `Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the ` + `query without any ML models: ${e}.`; From 061eaad743a00d6bd1f35c5b3600471cefc8537c Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 30 May 2022 18:32:11 -0700 Subject: [PATCH 2/2] Update extensions/ql-vscode/src/cli.ts Change version where precise ml-model resolution was introduced. --- extensions/ql-vscode/src/cli.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index cf36b0422b3..1478fe70b07 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -1270,8 +1270,7 @@ export class CliVersionConstraint { /** * CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging. */ - // TODO: This is not the right version yet - public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer('2.9.3'); +public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer('2.10.0'); /** * CLI version where the `--old-eval-stats` option to the query server was introduced.