From 7f32439786ed512f3dbac73bcd9212faabc858c7 Mon Sep 17 00:00:00 2001 From: Nora Date: Tue, 7 Mar 2023 10:25:30 +0000 Subject: [PATCH] split viewAst command --- extensions/ql-vscode/package.json | 20 +++++++++- extensions/ql-vscode/src/extension.ts | 57 ++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 69291cd3c..798453c05 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -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" }, { diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 55a3f3821..aed267809 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -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 { + 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",