Skip to content

Commit 6b4be93

Browse files
authored
Merge pull request #1363 from github/aeisenberg/resolve-ml-model
Add new support for resolve ml-models
2 parents 8ff21d6 + 061eaad commit 6b4be93

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 14 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,11 @@ 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+
public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer('2.10.0');
1274+
12671275
/**
12681276
* CLI version where the `--old-eval-stats` option to the query server was introduced.
12691277
*/
@@ -1339,6 +1347,10 @@ export class CliVersionConstraint {
13391347
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS);
13401348
}
13411349

1350+
async supportsPreciseResolveMlModels() {
1351+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS);
1352+
}
1353+
13421354
async supportsOldEvalStats() {
13431355
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS);
13441356
}

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)