Skip to content

Commit 2644d26

Browse files
committed
WIP: warm base database from VSCode
1 parent da9a011 commit 2644d26

File tree

12 files changed

+159
-6
lines changed

12 files changed

+159
-6
lines changed

extensions/.DS_Store

6 KB
Binary file not shown.

extensions/ql-vscode/.DS_Store

8 KB
Binary file not shown.

extensions/ql-vscode/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@
515515
"command": "codeQL.runQueryContextEditor",
516516
"title": "CodeQL: Run Query on Selected Database"
517517
},
518+
{
519+
"command": "codeQL.runPopulateUnderlayQuery",
520+
"title": "CodeQL: Populate Database Underlay for Query"
521+
},
522+
{
523+
"command": "codeQL.runPopulateUnderlayQueryContextEditor",
524+
"title": "CodeQL: Populate Database Underlay for Query"
525+
},
518526
{
519527
"command": "codeQL.debugQuery",
520528
"title": "CodeQL: Debug Query"
@@ -571,10 +579,18 @@
571579
"command": "codeQL.runQueries",
572580
"title": "CodeQL: Run Queries in Selected Files"
573581
},
582+
{
583+
"command": "codeQL.runPopulateUnderlayQueries",
584+
"title": "CodeQL: Populate Database Underlay for Queries in Selected Files"
585+
},
574586
{
575587
"command": "codeQL.runQuerySuite",
576588
"title": "CodeQL: Run Selected Query Suite"
577589
},
590+
{
591+
"command": "codeQL.runPopulateUnderlayQuerySuite",
592+
"title": "CodeQL: Populate Database Underlay for Query Suite"
593+
},
578594
{
579595
"command": "codeQL.quickEval",
580596
"title": "CodeQL: Quick Evaluation"
@@ -1378,11 +1394,21 @@
13781394
"group": "9_qlCommands",
13791395
"when": "resourceScheme != codeql-zip-archive"
13801396
},
1397+
{
1398+
"command": "codeQL.runPopulateUnderlayQueries",
1399+
"group": "9_qlCommands",
1400+
"when": "resourceScheme != codeql-zip-archive"
1401+
},
13811402
{
13821403
"command": "codeQL.runQuerySuite",
13831404
"group": "9_qlCommands",
13841405
"when": "resourceScheme != codeql-zip-archive && resourceExtname == .qls && !explorerResourceIsFolder && !listMultiSelection && config.codeQL.canary"
13851406
},
1407+
{
1408+
"command": "codeQL.runPopulateUnderlayQuerySuite",
1409+
"group": "9_qlCommands",
1410+
"when": "resourceScheme != codeql-zip-archive && resourceExtname == .qls && !explorerResourceIsFolder && !listMultiSelection && config.codeQL.canary"
1411+
},
13861412
{
13871413
"command": "codeQL.runVariantAnalysisContextExplorer",
13881414
"group": "9_qlCommands",
@@ -1408,6 +1434,10 @@
14081434
"command": "codeQL.runQuery",
14091435
"when": "resourceLangId == ql && resourceExtname == .ql"
14101436
},
1437+
{
1438+
"command": "codeQL.runPopulateUnderlayQuery",
1439+
"when": "resourceLangId == ql && resourceExtname == .ql"
1440+
},
14111441
{
14121442
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
14131443
"when": "false"
@@ -1428,6 +1458,10 @@
14281458
"command": "codeQL.runQueryContextEditor",
14291459
"when": "false"
14301460
},
1461+
{
1462+
"command": "codeQL.runPopulateUnderlayQueryContextEditor",
1463+
"when": "false"
1464+
},
14311465
{
14321466
"command": "codeQL.debugQuery",
14331467
"when": "config.codeQL.canary && editorLangId == ql && resourceExtname == .ql && !inDebugMode"
@@ -1480,10 +1514,18 @@
14801514
"command": "codeQL.runQueries",
14811515
"when": "false"
14821516
},
1517+
{
1518+
"command": "codeQL.runPopulateUnderlayQueries",
1519+
"when": "false"
1520+
},
14831521
{
14841522
"command": "codeQL.runQuerySuite",
14851523
"when": "false"
14861524
},
1525+
{
1526+
"command": "codeQL.runPopulateUnderlayQuerySuite",
1527+
"when": "false"
1528+
},
14871529
{
14881530
"command": "codeQL.quickEval",
14891531
"when": "editorLangId == ql"
@@ -1832,6 +1874,10 @@
18321874
"command": "codeQL.runQueryContextEditor",
18331875
"when": "editorLangId == ql && resourceExtname == .ql && !inDebugMode"
18341876
},
1877+
{
1878+
"command": "codeQL.runPopulateUnderlayQueryContextEditor",
1879+
"when": "editorLangId == ql && resourceExtname == .ql && !inDebugMode"
1880+
},
18351881
{
18361882
"command": "codeQL.runQueryOnMultipleDatabasesContextEditor",
18371883
"when": "editorLangId == ql && resourceExtname == .ql"

extensions/ql-vscode/src/common/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ export type QueryEditorCommands = {
126126
// Commands used for running local queries
127127
export type LocalQueryCommands = {
128128
"codeQL.runQuery": (uri?: Uri) => Promise<void>;
129+
"codeQL.runPopulateUnderlayQuery": (uri?: Uri) => Promise<void>;
129130
"codeQL.runQueryContextEditor": (uri?: Uri) => Promise<void>;
131+
"codeQL.runPopulateUnderlayQueryContextEditor": (uri?: Uri) => Promise<void>;
130132
"codeQL.runQueryOnMultipleDatabases": (uri?: Uri) => Promise<void>;
131133
"codeQL.runQueryOnMultipleDatabasesContextEditor": (
132134
uri?: Uri,
@@ -138,7 +140,9 @@ export type LocalQueryCommands = {
138140
"codeQLQueries.createQuery": () => Promise<void>;
139141
"codeQL.runLocalQueryFromFileTab": (uri: Uri) => Promise<void>;
140142
"codeQL.runQueries": ExplorerSelectionCommandFunction<Uri>;
143+
"codeQL.runPopulateUnderlayQueries": ExplorerSelectionCommandFunction<Uri>;
141144
"codeQL.runQuerySuite": ExplorerSelectionCommandFunction<Uri>;
145+
"codeQL.runPopulateUnderlayQuerySuite": ExplorerSelectionCommandFunction<Uri>;
142146
"codeQL.quickEval": (uri: Uri) => Promise<void>;
143147
"codeQL.quickEvalCount": (uri: Uri) => Promise<void>;
144148
"codeQL.quickEvalContextEditor": (uri: Uri) => Promise<void>;

extensions/ql-vscode/src/debugger/debug-session.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class RunningQuery extends DisposableObject {
172172
true,
173173
config.additionalPacks,
174174
config.extensionPacks,
175+
false,
176+
false,
177+
false,
175178
config.additionalRunQueryArgs,
176179
queryStorageDir,
177180
basename(config.query),

extensions/ql-vscode/src/language-support/ast-viewer/ast-cfg-commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function getAstCfgCommands({
5959
progress,
6060
token,
6161
undefined,
62+
false,
6263
undefined,
6364
res[1],
6465
);

extensions/ql-vscode/src/language-support/contextual/query-resolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export async function runContextualQuery(
9191
false,
9292
getOnDiskWorkspaceFolders(),
9393
undefined,
94+
false,
95+
false,
96+
false,
9497
{},
9598
queryStorageDir,
9699
basename(query),

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

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ export class LocalQueries extends DisposableObject {
9595
public getCommands(): LocalQueryCommands {
9696
return {
9797
"codeQL.runQuery": this.runQuery.bind(this),
98+
"codeQL.runPopulateUnderlayQuery":
99+
this.runPopulateUnderlayQuery.bind(this),
98100
"codeQL.runQueryContextEditor": this.runQuery.bind(this),
101+
"codeQL.runPopulateUnderlayQueryContextEditor":
102+
this.runPopulateUnderlayQuery.bind(this),
99103
"codeQL.runQueryOnMultipleDatabases":
100104
this.runQueryOnMultipleDatabases.bind(this),
101105
"codeQL.runQueryOnMultipleDatabasesContextEditor":
@@ -113,7 +117,12 @@ export class LocalQueries extends DisposableObject {
113117
"codeQL.runQueries": createMultiSelectionCommand(
114118
this.runQueries.bind(this),
115119
),
120+
"codeQL.runPopulateUnderlayQueries": createMultiSelectionCommand(
121+
this.runPopulateUnderlayQueries.bind(this),
122+
),
116123
"codeQL.runQuerySuite": this.runQuerySuite.bind(this),
124+
"codeQL.runPopulateUnderlayQuerySuite":
125+
this.runPopulateUnderlayQuerySuite.bind(this),
117126
"codeQL.quickEval": this.quickEval.bind(this),
118127
"codeQL.quickEvalCount": this.quickEvalCount.bind(this),
119128
"codeQL.quickEvalContextEditor": this.quickEval.bind(this),
@@ -152,6 +161,16 @@ export class LocalQueries extends DisposableObject {
152161
}
153162

154163
private async runQuery(uri: Uri | undefined): Promise<void> {
164+
await this.runQueryInternal(uri, false);
165+
}
166+
private async runPopulateUnderlayQuery(uri: Uri | undefined): Promise<void> {
167+
await this.runQueryInternal(uri, true);
168+
}
169+
170+
private async runQueryInternal(
171+
uri: Uri | undefined,
172+
onlyPopulateUnderlay: boolean,
173+
): Promise<void> {
155174
await withProgress(
156175
async (progress, token) => {
157176
await this.compileAndRunQuery(
@@ -160,10 +179,13 @@ export class LocalQueries extends DisposableObject {
160179
progress,
161180
token,
162181
undefined,
182+
onlyPopulateUnderlay,
163183
);
164184
},
165185
{
166-
title: "Running query",
186+
title: onlyPopulateUnderlay
187+
? "Populate database underlay for query"
188+
: "Running query",
167189
cancellable: true,
168190
},
169191
);
@@ -181,8 +203,18 @@ export class LocalQueries extends DisposableObject {
181203
},
182204
);
183205
}
184-
185206
private async runQueries(fileURIs: Uri[]): Promise<void> {
207+
await this.runQueriesInternal(fileURIs, false);
208+
}
209+
210+
private async runPopulateUnderlayQueries(fileURIs: Uri[]): Promise<void> {
211+
await this.runQueriesInternal(fileURIs, true);
212+
}
213+
214+
private async runQueriesInternal(
215+
fileURIs: Uri[],
216+
onlyPopulateUnderlay: boolean,
217+
): Promise<void> {
186218
await withProgress(
187219
async (progress, token) => {
188220
const maxQueryCount = MAX_QUERIES.getValue<number>();
@@ -235,18 +267,32 @@ export class LocalQueries extends DisposableObject {
235267
wrappedProgress,
236268
token,
237269
undefined,
270+
onlyPopulateUnderlay,
238271
).then(() => queriesRemaining--),
239272
),
240273
);
241274
},
242275
{
243-
title: "Running queries",
276+
title: onlyPopulateUnderlay
277+
? "Populate database underlay for queries"
278+
: "Running queries",
244279
cancellable: true,
245280
},
246281
);
247282
}
248283

249284
private async runQuerySuite(fileUri: Uri): Promise<void> {
285+
await this.runQuerySuiteInternal(fileUri, false);
286+
}
287+
288+
private async runPopulateUnderlayQuerySuite(fileUri: Uri): Promise<void> {
289+
await this.runQuerySuiteInternal(fileUri, true);
290+
}
291+
292+
private async runQuerySuiteInternal(
293+
fileUri: Uri,
294+
onlyPopulateUnderlay: boolean,
295+
): Promise<void> {
250296
await withProgress(
251297
async (progress, token) => {
252298
const suitePath = validateQuerySuiteUri(fileUri);
@@ -286,6 +332,9 @@ export class LocalQueries extends DisposableObject {
286332
true,
287333
additionalPacks,
288334
extensionPacks,
335+
onlyPopulateUnderlay,
336+
onlyPopulateUnderlay,
337+
onlyPopulateUnderlay,
289338
{},
290339
this.queryStorageDir,
291340
basename(suitePath),
@@ -310,7 +359,8 @@ export class LocalQueries extends DisposableObject {
310359
localQueryRun.logger,
311360
);
312361

313-
await localQueryRun.complete(results, progress);
362+
if (!onlyPopulateUnderlay)
363+
await localQueryRun.complete(results, progress);
314364

315365
return results;
316366
} catch (e) {
@@ -328,7 +378,9 @@ export class LocalQueries extends DisposableObject {
328378
}
329379
},
330380
{
331-
title: "Running query suite",
381+
title: onlyPopulateUnderlay
382+
? "Populate database underlay for query suite"
383+
: "Running query suite",
332384
cancellable: true,
333385
},
334386
);
@@ -343,6 +395,7 @@ export class LocalQueries extends DisposableObject {
343395
progress,
344396
token,
345397
undefined,
398+
false,
346399
);
347400
},
348401
{
@@ -361,6 +414,7 @@ export class LocalQueries extends DisposableObject {
361414
progress,
362415
token,
363416
undefined,
417+
false,
364418
);
365419
},
366420
{
@@ -379,6 +433,7 @@ export class LocalQueries extends DisposableObject {
379433
progress,
380434
token,
381435
undefined,
436+
false,
382437
range,
383438
),
384439
{
@@ -489,6 +544,7 @@ export class LocalQueries extends DisposableObject {
489544
progress: ProgressCallback,
490545
token: CancellationToken,
491546
databaseItem: DatabaseItem | undefined,
547+
onlyPopulateUnderlay: boolean,
492548
range?: Range,
493549
templates?: Record<string, string>,
494550
): Promise<void> {
@@ -500,6 +556,7 @@ export class LocalQueries extends DisposableObject {
500556
databaseItem,
501557
range,
502558
templates,
559+
onlyPopulateUnderlay,
503560
);
504561
}
505562

@@ -512,6 +569,7 @@ export class LocalQueries extends DisposableObject {
512569
databaseItem: DatabaseItem | undefined,
513570
range?: Range,
514571
templates?: Record<string, string>,
572+
onlyPopulateUnderlay: boolean = false,
515573
): Promise<CoreCompletedQuery> {
516574
await saveBeforeStart();
517575

@@ -558,6 +616,9 @@ export class LocalQueries extends DisposableObject {
558616
true,
559617
additionalPacks,
560618
extensionPacks,
619+
onlyPopulateUnderlay,
620+
onlyPopulateUnderlay,
621+
onlyPopulateUnderlay,
561622
{},
562623
this.queryStorageDir,
563624
basename(selectedQuery.queryPath),
@@ -583,7 +644,8 @@ export class LocalQueries extends DisposableObject {
583644
localQueryRun.logger,
584645
);
585646

586-
await localQueryRun.complete(results, progress);
647+
if (!onlyPopulateUnderlay)
648+
await localQueryRun.complete(results, progress);
587649

588650
return results;
589651
} catch (e) {
@@ -656,6 +718,7 @@ export class LocalQueries extends DisposableObject {
656718
progress,
657719
token,
658720
item.databaseItem,
721+
false,
659722
);
660723
} catch (e) {
661724
skippedDatabases.push(item.label);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export async function runQuery({
4444
false,
4545
additionalPacks,
4646
extensionPacks,
47+
false,
48+
false,
49+
false,
4750
{},
4851
queryStorageDir,
4952
basename(queryPath),

0 commit comments

Comments
 (0)