split viewAst command

This commit is contained in:
Nora
2023-03-07 10:25:30 +00:00
parent 27434862c3
commit 7f32439786
2 changed files with 66 additions and 11 deletions

View File

@@ -437,6 +437,14 @@
"command": "codeQL.viewAst",
"title": "CodeQL: View AST"
},
{
"command": "codeQL.viewAstContextExplorer",
"title": "CodeQL: View AST"
},
{
"command": "codeQL.viewAstContextEditor",
"title": "CodeQL: View AST"
},
{
"command": "codeQL.viewCfg",
"title": "CodeQL: View CFG"
@@ -934,7 +942,7 @@
"when": "resourceScheme == codeql-zip-archive || explorerResourceIsFolder || resourceExtname == .zip"
},
{
"command": "codeQL.viewAst",
"command": "codeQL.viewAstContextExplorer",
"group": "9_qlCommands",
"when": "resourceScheme == codeql-zip-archive && !explorerResourceIsFolder && !listMultiSelection"
},
@@ -1012,6 +1020,14 @@
"command": "codeQL.viewAst",
"when": "resourceScheme == codeql-zip-archive"
},
{
"command": "codeQL.viewAstContextEditor",
"when": "false"
},
{
"command": "codeQL.viewAstContextExplorer",
"when": "false"
},
{
"command": "codeQL.viewCfg",
"when": "resourceScheme == codeql-zip-archive && config.codeQL.canary"
@@ -1243,7 +1259,7 @@
"when": "editorLangId == ql && resourceExtname == .ql"
},
{
"command": "codeQL.viewAst",
"command": "codeQL.viewAstContextEditor",
"when": "resourceScheme == codeql-zip-archive"
},
{

View File

@@ -1495,6 +1495,22 @@ async function activateWithInstalledDistribution(
const cfgTemplateProvider = new TemplatePrintCfgProvider(cliServer, dbm);
ctx.subscriptions.push(astViewer);
async function viewAst(
progress: ProgressCallback,
token: CancellationToken,
selectedFile: Uri,
): Promise<void> {
const ast = await printAstTemplateProvider.provideAst(
progress,
token,
selectedFile ?? window.activeTextEditor?.document.uri,
);
if (ast) {
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
}
}
ctx.subscriptions.push(
commandRunnerWithProgress(
"codeQL.viewAst",
@@ -1502,16 +1518,39 @@ async function activateWithInstalledDistribution(
progress: ProgressCallback,
token: CancellationToken,
selectedFile: Uri,
) => {
const ast = await printAstTemplateProvider.provideAst(
progress,
token,
selectedFile ?? window.activeTextEditor?.document.uri,
);
if (ast) {
astViewer.updateRoots(await ast.getRoots(), ast.db, ast.fileName);
}
) => await viewAst(progress, token, selectedFile),
{
cancellable: true,
title: "Calculate AST",
},
),
);
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.viewAst" command
ctx.subscriptions.push(
commandRunnerWithProgress(
"codeQL.viewAstContextExplorer",
async (
progress: ProgressCallback,
token: CancellationToken,
selectedFile: Uri,
) => await viewAst(progress, token, selectedFile),
{
cancellable: true,
title: "Calculate AST",
},
),
);
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.viewAst" command
ctx.subscriptions.push(
commandRunnerWithProgress(
"codeQL.viewAstContextEditor",
async (
progress: ProgressCallback,
token: CancellationToken,
selectedFile: Uri,
) => await viewAst(progress, token, selectedFile),
{
cancellable: true,
title: "Calculate AST",