Skip to content

Commit 66825d6

Browse files
committed
Add command for running queries on multiple databases
1 parent d42982e commit 66825d6

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

extensions/ql-vscode/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
"command": "codeQL.runQuery",
246246
"title": "CodeQL: Run Query"
247247
},
248+
{
249+
"command": "codeQL.runQueryOnMultipleDatabases",
250+
"title": "CodeQL: Run Query on Multiple Databases"
251+
},
248252
{
249253
"command": "codeQL.runRemoteQuery",
250254
"title": "CodeQL: Run Remote Query"
@@ -680,6 +684,10 @@
680684
"command": "codeQL.runQuery",
681685
"when": "resourceLangId == ql && resourceExtname == .ql"
682686
},
687+
{
688+
"command": "codeQL.runQueryOnMultipleDatabases",
689+
"when": "resourceLangId == ql && resourceExtname == .ql"
690+
},
683691
{
684692
"command": "codeQL.runRemoteQuery",
685693
"when": "config.codeQL.canary && editorLangId == ql && resourceExtname == .ql"
@@ -830,6 +838,10 @@
830838
"command": "codeQL.runQuery",
831839
"when": "editorLangId == ql && resourceExtname == .ql"
832840
},
841+
{
842+
"command": "codeQL.runQueryOnMultipleDatabases",
843+
"when": "editorLangId == ql && resourceExtname == .ql"
844+
},
833845
{
834846
"command": "codeQL.runRemoteQuery",
835847
"when": "config.codeQL.canary && editorLangId == ql && resourceExtname == .ql"

extensions/ql-vscode/src/extension.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
QueryServerConfigListener
3030
} from './config';
3131
import * as languageSupport from './languageSupport';
32-
import { DatabaseManager } from './databases';
32+
import { DatabaseItem, DatabaseManager } from './databases';
3333
import { DatabaseUI } from './databases-ui';
3434
import {
3535
TemplateQueryDefinitionProvider,
@@ -467,9 +467,12 @@ async function activateWithInstalledDistribution(
467467
selectedQuery: Uri | undefined,
468468
progress: ProgressCallback,
469469
token: CancellationToken,
470+
databaseQuickPick: DatabaseItem | undefined,
470471
): Promise<void> {
471472
if (qs !== undefined) {
472-
const dbItem = await databaseUI.getDatabaseItem(progress, token);
473+
const dbItem = databaseQuickPick !== undefined
474+
? databaseQuickPick
475+
: await databaseUI.getDatabaseItem(progress, token);
473476
if (dbItem === undefined) {
474477
throw new Error('Can\'t run query without a selected database');
475478
}
@@ -549,13 +552,46 @@ async function activateWithInstalledDistribution(
549552
progress: ProgressCallback,
550553
token: CancellationToken,
551554
uri: Uri | undefined
552-
) => await compileAndRunQuery(false, uri, progress, token),
555+
) => await compileAndRunQuery(false, uri, progress, token, undefined),
553556
{
554557
title: 'Running query',
555558
cancellable: true
556559
}
557560
)
558561
);
562+
ctx.subscriptions.push(
563+
commandRunnerWithProgress(
564+
'codeQL.runQueryOnMultipleDatabases',
565+
async (
566+
progress: ProgressCallback,
567+
token: CancellationToken,
568+
uri: Uri | undefined
569+
) => {
570+
/**
571+
* Databases selected from the quick pick menu.
572+
*/
573+
const quickpick = await window.showQuickPick(
574+
// TODO: Return items of type "DatabaseItem" instead of "string"
575+
// For this to work, I think we need "DatabaseItem" to extend "QuickPickItem":
576+
// https://code.visualstudio.com/api/references/vscode-api#QuickPickItem
577+
dbm.databaseItems.map(dbItem => dbItem.name),
578+
{ canPickMany: true },
579+
);
580+
if (quickpick !== undefined) {
581+
for (const item of quickpick) {
582+
// Instead of "item" (which is a string), we need the associated "DatabaseItem"...
583+
await compileAndRunQuery(false, uri, progress, token, item);
584+
}
585+
} else {
586+
void helpers.showAndLogErrorMessage('No databases selected.');
587+
}
588+
},
589+
{
590+
title: 'Running query on selected databases',
591+
cancellable: true
592+
}
593+
)
594+
);
559595
ctx.subscriptions.push(
560596
commandRunnerWithProgress(
561597
'codeQL.runQueries',
@@ -611,7 +647,7 @@ async function activateWithInstalledDistribution(
611647
});
612648

613649
await Promise.all(queryUris.map(async uri =>
614-
compileAndRunQuery(false, uri, wrappedProgress, token)
650+
compileAndRunQuery(false, uri, wrappedProgress, token, undefined)
615651
.then(() => queriesRemaining--)
616652
));
617653
},
@@ -627,7 +663,7 @@ async function activateWithInstalledDistribution(
627663
progress: ProgressCallback,
628664
token: CancellationToken,
629665
uri: Uri | undefined
630-
) => await compileAndRunQuery(true, uri, progress, token),
666+
) => await compileAndRunQuery(true, uri, progress, token, undefined),
631667
{
632668
title: 'Running query',
633669
cancellable: true

0 commit comments

Comments
 (0)