Skip to content

Commit 7f32439

Browse files
committed
split viewAst command
1 parent 2743486 commit 7f32439

2 files changed

Lines changed: 66 additions & 11 deletions

File tree

extensions/ql-vscode/package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@
437437
"command": "codeQL.viewAst",
438438
"title": "CodeQL: View AST"
439439
},
440+
{
441+
"command": "codeQL.viewAstContextExplorer",
442+
"title": "CodeQL: View AST"
443+
},
444+
{
445+
"command": "codeQL.viewAstContextEditor",
446+
"title": "CodeQL: View AST"
447+
},
440448
{
441449
"command": "codeQL.viewCfg",
442450
"title": "CodeQL: View CFG"
@@ -934,7 +942,7 @@
934942
"when": "resourceScheme == codeql-zip-archive || explorerResourceIsFolder || resourceExtname == .zip"
935943
},
936944
{
937-
"command": "codeQL.viewAst",
945+
"command": "codeQL.viewAstContextExplorer",
938946
"group": "9_qlCommands",
939947
"when": "resourceScheme == codeql-zip-archive && !explorerResourceIsFolder && !listMultiSelection"
940948
},
@@ -1012,6 +1020,14 @@
10121020
"command": "codeQL.viewAst",
10131021
"when": "resourceScheme == codeql-zip-archive"
10141022
},
1023+
{
1024+
"command": "codeQL.viewAstContextEditor",
1025+
"when": "false"
1026+
},
1027+
{
1028+
"command": "codeQL.viewAstContextExplorer",
1029+
"when": "false"
1030+
},
10151031
{
10161032
"command": "codeQL.viewCfg",
10171033
"when": "resourceScheme == codeql-zip-archive && config.codeQL.canary"
@@ -1243,7 +1259,7 @@
12431259
"when": "editorLangId == ql && resourceExtname == .ql"
12441260
},
12451261
{
1246-
"command": "codeQL.viewAst",
1262+
"command": "codeQL.viewAstContextEditor",
12471263
"when": "resourceScheme == codeql-zip-archive"
12481264
},
12491265
{

extensions/ql-vscode/src/extension.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,23 +1495,62 @@ async function activateWithInstalledDistribution(
14951495
const cfgTemplateProvider = new TemplatePrintCfgProvider(cliServer, dbm);
14961496

14971497
ctx.subscriptions.push(astViewer);
1498+
1499+
async function viewAst(
1500+
progress: ProgressCallback,
1501+
token: CancellationToken,
1502+
selectedFile: Uri,
1503+
): Promise<void> {
1504+
const ast = await printAstTemplateProvider.provideAst(
1505+
progress,
1506+
token,
1507+
selectedFile ?? window.activeTextEditor?.document.uri,
1508+
);
1509+
if (ast) {
1510+
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
1511+
}
1512+
}
1513+
14981514
ctx.subscriptions.push(
14991515
commandRunnerWithProgress(
15001516
"codeQL.viewAst",
15011517
async (
15021518
progress: ProgressCallback,
15031519
token: CancellationToken,
15041520
selectedFile: Uri,
1505-
) => {
1506-
const ast = await printAstTemplateProvider.provideAst(
1507-
progress,
1508-
token,
1509-
selectedFile ?? window.activeTextEditor?.document.uri,
1510-
);
1511-
if (ast) {
1512-
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
1513-
}
1521+
) => await viewAst(progress, token, selectedFile),
1522+
{
1523+
cancellable: true,
1524+
title: "Calculate AST",
1525+
},
1526+
),
1527+
);
1528+
1529+
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.viewAst" command
1530+
ctx.subscriptions.push(
1531+
commandRunnerWithProgress(
1532+
"codeQL.viewAstContextExplorer",
1533+
async (
1534+
progress: ProgressCallback,
1535+
token: CancellationToken,
1536+
selectedFile: Uri,
1537+
) => await viewAst(progress, token, selectedFile),
1538+
{
1539+
cancellable: true,
1540+
title: "Calculate AST",
15141541
},
1542+
),
1543+
);
1544+
1545+
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.viewAst" command
1546+
ctx.subscriptions.push(
1547+
commandRunnerWithProgress(
1548+
"codeQL.viewAstContextEditor",
1549+
async (
1550+
progress: ProgressCallback,
1551+
token: CancellationToken,
1552+
selectedFile: Uri,
1553+
) => await viewAst(progress, token, selectedFile),
15151554
{
15161555
cancellable: true,
15171556
title: "Calculate AST",

0 commit comments

Comments
 (0)