Skip to content

Commit 8e817ee

Browse files
committed
Refactor the commandRunner
Split commandRunner into two functions: commandRunner and commandRunnerWithProgress. Also, take advantage of default arguments for ProgressOptions. And updates changelog.
1 parent e5d439a commit 8e817ee

7 files changed

Lines changed: 122 additions & 100 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
- Add friendly welcome message when the databases view is empty.
66
- Add open query, open results, and remove query commands in the query history view title bar.
7-
- Max number of simultaneous queries launchable by runQueries command is now configurable by changing the `codeQL.runningQueries.maxQueries` setting.
7+
- The maximum number of simultaneous queries launchable by the `CodeQL: Run Queries in Selected Files` command is now configurable by changing the `codeQL.runningQueries.maxQueries` setting.
88
- Allow simultaneously run queries to be canceled in a single-click.
99
- Prevent multiple upgrade dialogs from appearing when running simultaneous queries on upgradeable databases.
10-
- Allow simultaneously run queries to be canceled in a single-click.
11-
- Max number of simultaneous queries launchable by runQueries command is now configurable by changing the codeQL.runningQueries.maxQueries setting.
1210
- Fix sorting of results. Some pages of results would have the wrong sort order and columns.
1311
- Remember previous sort order when reloading query results.
1412
- Fix proper escaping of backslashes in SARIF message strings.

extensions/ql-vscode/src/astViewer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { showLocation } from './interface-utils';
2020
import { isStringLoc, isWholeFileLoc, isLineColumnLoc } from './bqrs-utils';
2121
import { commandRunner } from './helpers';
2222

23-
2423
export interface AstItem {
2524
id: BqrsId;
2625
label?: string;

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class TemplateQueryDefinitionProvider implements vscode.DefinitionProvide
4444
}
4545

4646
private async getDefinitions(uriString: string): Promise<vscode.LocationLink[]> {
47-
return await withProgress({
47+
return withProgress({
4848
location: vscode.ProgressLocation.Notification,
4949
cancellable: true,
5050
title: 'Finding definitions'
@@ -91,7 +91,7 @@ export class TemplateQueryReferenceProvider implements vscode.ReferenceProvider
9191
}
9292

9393
private async getReferences(uriString: string): Promise<FullLocationLink[]> {
94-
return await withProgress({
94+
return withProgress({
9595
location: vscode.ProgressLocation.Notification,
9696
cancellable: true,
9797
title: 'Finding references'

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
TreeItem,
1010
Uri,
1111
window,
12-
env,
13-
ProgressLocation
12+
env
1413
} from 'vscode';
1514
import * as fs from 'fs-extra';
1615

@@ -23,6 +22,7 @@ import {
2322
} from './databases';
2423
import {
2524
commandRunner,
25+
commandRunnerWithProgress,
2626
getOnDiskWorkspaceFolders,
2727
ProgressCallback,
2828
showAndLogErrorMessage
@@ -233,79 +233,66 @@ export class DatabaseUI extends DisposableObject {
233233

234234
logger.log('Registering database panel commands.');
235235
ctx.subscriptions.push(
236-
commandRunner(
236+
commandRunnerWithProgress(
237237
'codeQL.setCurrentDatabase',
238238
this.handleSetCurrentDatabase,
239239
{
240-
location: ProgressLocation.Notification,
241240
title: 'Importing database from archive',
242-
cancellable: false,
243241
}
244242
)
245243
);
246244
ctx.subscriptions.push(
247-
commandRunner(
245+
commandRunnerWithProgress(
248246
'codeQL.upgradeCurrentDatabase',
249247
this.handleUpgradeCurrentDatabase,
250248
{
251-
location: ProgressLocation.Notification,
252249
title: 'Upgrading current database',
253250
cancellable: true,
254251
}
255252
)
256253
);
257254
ctx.subscriptions.push(
258-
commandRunner(
255+
commandRunnerWithProgress(
259256
'codeQL.clearCache',
260257
this.handleClearCache,
261258
{
262-
location: ProgressLocation.Notification,
263259
title: 'Clearing Cache',
264-
cancellable: false,
265260
})
266261
);
267262

268263
ctx.subscriptions.push(
269-
commandRunner(
264+
commandRunnerWithProgress(
270265
'codeQLDatabases.chooseDatabaseFolder',
271266
this.handleChooseDatabaseFolder,
272267
{
273-
location: ProgressLocation.Notification,
274268
title: 'Adding database from folder',
275-
cancellable: false,
276269
}
277270
)
278271
);
279272
ctx.subscriptions.push(
280-
commandRunner(
273+
commandRunnerWithProgress(
281274
'codeQLDatabases.chooseDatabaseArchive',
282275
this.handleChooseDatabaseArchive,
283276
{
284-
location: ProgressLocation.Notification,
285277
title: 'Adding database from archive',
286-
cancellable: false,
287278
}
288279
)
289280
);
290281
ctx.subscriptions.push(
291-
commandRunner(
282+
commandRunnerWithProgress(
292283
'codeQLDatabases.chooseDatabaseInternet',
293284
this.handleChooseDatabaseInternet,
294285
{
295-
location: ProgressLocation.Notification,
296286
title: 'Adding database from URL',
297-
cancellable: false,
298287
}
299288
)
300289
);
301290
ctx.subscriptions.push(
302-
commandRunner(
291+
commandRunnerWithProgress(
303292
'codeQLDatabases.chooseDatabaseLgtm',
304293
this.handleChooseDatabaseLgtm,
305294
{
306-
location: ProgressLocation.Notification,
307295
title: 'Adding database from LGTM',
308-
cancellable: false,
309296
})
310297
);
311298
ctx.subscriptions.push(
@@ -333,11 +320,10 @@ export class DatabaseUI extends DisposableObject {
333320
)
334321
);
335322
ctx.subscriptions.push(
336-
commandRunner(
323+
commandRunnerWithProgress(
337324
'codeQLDatabases.upgradeDatabase',
338325
this.handleUpgradeDatabase,
339326
{
340-
location: ProgressLocation.Notification,
341327
title: 'Upgrading database',
342328
cancellable: true,
343329
}
@@ -522,9 +508,9 @@ export class DatabaseUI extends DisposableObject {
522508
};
523509

524510
private handleSetCurrentDatabase = async (
525-
uri: Uri,
526511
progress: ProgressCallback,
527512
token: CancellationToken,
513+
uri: Uri,
528514
): Promise<void> => {
529515
try {
530516
// Assume user has selected an archive if the file has a .zip extension

extensions/ql-vscode/src/extension.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,10 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
165165
}
166166
} else {
167167
const progressOptions: ProgressOptions = {
168-
location: ProgressLocation.Notification,
169168
title: progressTitle,
170-
cancellable: false,
169+
location: ProgressLocation.Notification,
171170
};
172171

173-
// Avoid using commandRunner here because this function is called upon extension activation
174172
await helpers.withProgress(progressOptions, progress =>
175173
distributionManager.installExtensionManagedDistributionRelease(result.updatedRelease, progress));
176174

@@ -459,22 +457,21 @@ async function activateWithInstalledDistribution(
459457

460458
logger.log('Registering top-level command palette commands.');
461459
ctx.subscriptions.push(
462-
helpers.commandRunner(
460+
helpers.commandRunnerWithProgress(
463461
'codeQL.runQuery',
464462
async (
465463
progress: helpers.ProgressCallback,
466464
token: CancellationToken,
467465
uri: Uri | undefined
468466
) => await compileAndRunQuery(false, uri, progress, token),
469467
{
470-
location: ProgressLocation.Notification,
471468
title: 'Running query',
472469
cancellable: true
473470
}
474471
)
475472
);
476473
ctx.subscriptions.push(
477-
helpers.commandRunner(
474+
helpers.commandRunnerWithProgress(
478475
'codeQL.runQueries',
479476
async (
480477
progress: helpers.ProgressCallback,
@@ -533,31 +530,32 @@ async function activateWithInstalledDistribution(
533530
));
534531
},
535532
{
536-
location: ProgressLocation.Notification,
537533
title: 'Running queries',
538534
cancellable: true
539535
})
540536
);
541537
ctx.subscriptions.push(
542-
helpers.commandRunner(
538+
helpers.commandRunnerWithProgress(
543539
'codeQL.quickEval',
544540
async (
545541
progress: helpers.ProgressCallback,
546542
token: CancellationToken,
547543
uri: Uri | undefined
548544
) => await compileAndRunQuery(true, uri, progress, token),
549545
{
550-
location: ProgressLocation.Notification,
551546
title: 'Running query',
552547
cancellable: true
553548
})
554549
);
555550
ctx.subscriptions.push(
556-
helpers.commandRunner('codeQL.quickQuery', async (
551+
helpers.commandRunnerWithProgress('codeQL.quickQuery', async (
557552
progress: helpers.ProgressCallback,
558553
token: CancellationToken
559554
) =>
560-
displayQuickQuery(ctx, cliServer, databaseUI, progress, token)
555+
displayQuickQuery(ctx, cliServer, databaseUI, progress, token),
556+
{
557+
title: 'Run Quick Query'
558+
}
561559
)
562560
);
563561

@@ -586,28 +584,24 @@ async function activateWithInstalledDistribution(
586584
)
587585
);
588586
ctx.subscriptions.push(
589-
helpers.commandRunner('codeQL.chooseDatabaseLgtm', (
587+
helpers.commandRunnerWithProgress('codeQL.chooseDatabaseLgtm', (
590588
progress: helpers.ProgressCallback,
591589
token: CancellationToken
592590
) =>
593591
databaseUI.handleChooseDatabaseLgtm(progress, token),
594592
{
595-
location: ProgressLocation.Notification,
596593
title: 'Adding database from LGTM',
597-
cancellable: false,
598594
})
599595
);
600596
ctx.subscriptions.push(
601-
helpers.commandRunner('codeQL.chooseDatabaseInternet', (
597+
helpers.commandRunnerWithProgress('codeQL.chooseDatabaseInternet', (
602598
progress: helpers.ProgressCallback,
603599
token: CancellationToken
604600
) =>
605601
databaseUI.handleChooseDatabaseInternet(progress, token),
606602

607603
{
608-
location: ProgressLocation.Notification,
609604
title: 'Adding database from URL',
610-
cancellable: false,
611605
})
612606
);
613607

@@ -627,7 +621,7 @@ async function activateWithInstalledDistribution(
627621
);
628622

629623
const astViewer = new AstViewer(ctx);
630-
ctx.subscriptions.push(helpers.commandRunner('codeQL.viewAst', async (
624+
ctx.subscriptions.push(helpers.commandRunnerWithProgress('codeQL.viewAst', async (
631625
progress: helpers.ProgressCallback,
632626
token: CancellationToken
633627
) => {
@@ -637,7 +631,6 @@ async function activateWithInstalledDistribution(
637631
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
638632
}
639633
}, {
640-
location: ProgressLocation.Notification,
641634
cancellable: true,
642635
title: 'Calculate AST'
643636
}));

0 commit comments

Comments
 (0)