Skip to content

Commit 8d9a470

Browse files
committed
Allow running queries with templates
1 parent dfab590 commit 8d9a470

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

extensions/ql-vscode/src/messages.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ export interface EvaluateQueriesParams {
619619
useSequenceHint: boolean;
620620
}
621621

622+
export type TemplateDefinitions = { [key: string]: TemplateSource; }
623+
622624
/**
623625
* A single query that should be run
624626
*/
@@ -642,7 +644,7 @@ export interface QueryToRun {
642644
/**
643645
* Values to set for each template
644646
*/
645-
templateValues?: { [key: string]: TemplateSource; };
647+
templateValues?: TemplateDefinitions;
646648
/**
647649
* Whether templates without values in the templateValues
648650
* map should be set to the empty set or give an error.

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class QueryInfo {
5454
public readonly queryDbscheme: string, // the dbscheme file the query expects, based on library path resolution
5555
public readonly quickEvalPosition?: messages.Position,
5656
public readonly metadata?: QueryMetadata,
57+
public readonly templates?: messages.TemplateDefinitions,
5758
) {
5859
this.queryID = QueryInfo.nextQueryId++;
5960
this.compiledQueryPath = path.join(tmpDir.name, `compiledQuery${this.queryID}.qlo`);
@@ -78,6 +79,7 @@ export class QueryInfo {
7879
resultsPath: this.resultsPaths.resultsPath,
7980
qlo: vscode.Uri.file(this.compiledQueryPath).toString(),
8081
allowUnknownTemplates: true,
82+
templateValues: this.templates,
8183
id: callbackId,
8284
timeoutSecs: qs.config.timeoutSecs,
8385
}
@@ -355,7 +357,8 @@ export async function compileAndRunQueryAgainstDatabase(
355357
qs: qsClient.QueryServerClient,
356358
db: DatabaseItem,
357359
quickEval: boolean,
358-
selectedQueryUri: vscode.Uri | undefined
360+
selectedQueryUri: vscode.Uri | undefined,
361+
templates?: messages.TemplateDefinitions,
359362
): Promise<QueryWithResults> {
360363

361364
if (!db.contents || !db.contents.dbSchemeUri) {
@@ -408,7 +411,7 @@ export async function compileAndRunQueryAgainstDatabase(
408411
logger.log(`Couldn't resolve metadata for ${qlProgram.queryPath}: ${e}`);
409412
}
410413

411-
const query = new QueryInfo(qlProgram, db, packConfig.dbscheme, quickEvalPosition, metadata);
414+
const query = new QueryInfo(qlProgram, db, packConfig.dbscheme, quickEvalPosition, metadata, templates);
412415
await checkDbschemeCompatibility(cliServer, qs, query);
413416

414417
const errors = await query.compile(qs);

0 commit comments

Comments
 (0)