Skip to content

Commit 90ec003

Browse files
committed
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.
1 parent 2f9aca7 commit 90ec003

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,13 @@ export class CodeQLCliServer implements Disposable {
604604
}
605605

606606
/** Resolves the ML models that should be available when evaluating a query. */
607-
async resolveMlModels(additionalPacks: string[]): Promise<MlModelsInfo> {
607+
async resolveMlModels(additionalPacks: string[], queryPath: string): Promise<MlModelsInfo> {
608+
const args = await this.cliConstraints.supportsPreciseResolveMlModels()
609+
? [...this.getAdditionalPacksArg(additionalPacks), queryPath]
610+
: this.getAdditionalPacksArg(additionalPacks);
608611
return await this.runJsonCodeQlCliCommand<MlModelsInfo>(
609612
['resolve', 'ml-models'],
610-
this.getAdditionalPacksArg(additionalPacks),
613+
args,
611614
'Resolving ML models',
612615
false
613616
);
@@ -1264,6 +1267,12 @@ export class CliVersionConstraint {
12641267
*/
12651268
public static CLI_VERSION_WITH_RESOLVE_ML_MODELS = new SemVer('2.7.3');
12661269

1270+
/**
1271+
* CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging.
1272+
*/
1273+
// TODO: This is not the right version yet
1274+
public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer('2.9.3');
1275+
12671276
/**
12681277
* CLI version where the `--old-eval-stats` option to the query server was introduced.
12691278
*/
@@ -1339,6 +1348,10 @@ export class CliVersionConstraint {
13391348
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS);
13401349
}
13411350

1351+
async supportsPreciseResolveMlModels() {
1352+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS);
1353+
}
1354+
13421355
async supportsOldEvalStats() {
13431356
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS);
13441357
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class QueryEvaluationInfo {
174174
db: dataset,
175175
logPath: this.evalLogPath,
176176
});
177-
177+
178178
}
179179
const params: messages.EvaluateQueriesParams = {
180180
db: dataset,
@@ -204,7 +204,7 @@ export class QueryEvaluationInfo {
204204
queryInfo.evalLogSummaryLocation = this.evalLogSummaryPath;
205205
fs.readFile(this.evalLogEndSummaryPath, (err, buffer) => {
206206
if (err) {
207-
throw new Error(`Could not read structured evaluator log end of summary file at ${this.evalLogEndSummaryPath}.`);
207+
throw new Error(`Could not read structured evaluator log end of summary file at ${this.evalLogEndSummaryPath}.`);
208208
}
209209
void qs.logger.log(' --- Evaluator Log Summary --- ', { additionalLogLocation: this.logPath });
210210
void qs.logger.log(buffer.toString(), { additionalLogLocation: this.logPath });
@@ -334,7 +334,7 @@ export class QueryEvaluationInfo {
334334
/**
335335
* Holds if this query already has a completed structured evaluator log
336336
*/
337-
async hasEvalLog(): Promise<boolean> {
337+
async hasEvalLog(): Promise<boolean> {
338338
return fs.pathExists(this.evalLogPath);
339339
}
340340

@@ -755,8 +755,12 @@ export async function compileAndRunQueryAgainstDatabase(
755755
let availableMlModels: cli.MlModelInfo[] = [];
756756
if (await cliServer.cliConstraints.supportsResolveMlModels()) {
757757
try {
758-
availableMlModels = (await cliServer.resolveMlModels(diskWorkspaceFolders)).models;
759-
void logger.log(`Found available ML models at the following paths: ${availableMlModels.map(x => `'${x.path}'`).join(', ')}.`);
758+
availableMlModels = (await cliServer.resolveMlModels(diskWorkspaceFolders, initialInfo.queryPath)).models;
759+
if (availableMlModels.length) {
760+
void logger.log(`Found available ML models at the following paths: ${availableMlModels.map(x => `'${x.path}'`).join(', ')}.`);
761+
} else {
762+
void logger.log('Did not find any available ML models.');
763+
}
760764
} catch (e) {
761765
const message = `Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the ` +
762766
`query without any ML models: ${e}.`;

0 commit comments

Comments
 (0)