From 1bc560518f21874c48603a89544b0d6ff4facb40 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 15 Jan 2024 17:07:41 +0000 Subject: [PATCH] Add codeQL.runVariantAnalysisContextExplorer command --- extensions/ql-vscode/package.json | 13 +++++++++++++ extensions/ql-vscode/src/common/commands.ts | 1 + .../variant-analysis/variant-analysis-manager.ts | 12 +++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 01b09c4b5..26ad8d42e 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -545,6 +545,10 @@ "command": "codeQL.runVariantAnalysisContextEditor", "title": "CodeQL: Run Variant Analysis" }, + { + "command": "codeQL.runVariantAnalysisContextExplorer", + "title": "CodeQL: Run Variant Analysis" + }, { "command": "codeQL.exportSelectedVariantAnalysisResults", "title": "CodeQL: Export Variant Analysis Results" @@ -1321,6 +1325,11 @@ "group": "9_qlCommands", "when": "resourceScheme != codeql-zip-archive" }, + { + "command": "codeQL.runVariantAnalysisContextExplorer", + "group": "9_qlCommands", + "when": "resourceExtname == .ql && config.codeQL.canary && config.codeQL.variantAnalysis.multiQuery" + }, { "command": "codeQL.openReferencedFileContextExplorer", "group": "9_qlCommands", @@ -1397,6 +1406,10 @@ "command": "codeQL.runVariantAnalysis", "when": "editorLangId == ql && resourceExtname == .ql" }, + { + "command": "codeQL.runVariantAnalysisContextExplorer", + "when": "false" + }, { "command": "codeQL.runVariantAnalysisContextEditor", "when": "false" diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index 57c471ec7..d22768b59 100644 --- a/extensions/ql-vscode/src/common/commands.ts +++ b/extensions/ql-vscode/src/common/commands.ts @@ -277,6 +277,7 @@ export type VariantAnalysisCommands = { ) => Promise; "codeQL.runVariantAnalysis": (uri?: Uri) => Promise; "codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise; + "codeQL.runVariantAnalysisContextExplorer": ExplorerSelectionCommandFunction; "codeQLQueries.runVariantAnalysisContextMenu": TreeViewContextSingleSelectionCommandFunction; }; diff --git a/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts b/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts index 654e4c0ad..294d1ca24 100644 --- a/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts +++ b/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts @@ -86,6 +86,7 @@ import { import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item"; import { RequestError } from "@octokit/request-error"; import { handleRequestError } from "./custom-errors"; +import { createMultiSelectionCommand } from "../common/vscode/selection-commands"; const maxRetryCount = 3; @@ -167,9 +168,11 @@ export class VariantAnalysisManager "codeQL.openVariantAnalysisView": this.showView.bind(this), "codeQL.runVariantAnalysis": this.runVariantAnalysisFromCommand.bind(this), - // Since we are tracking extension usage through commands, this command mirrors the "codeQL.runVariantAnalysis" command "codeQL.runVariantAnalysisContextEditor": this.runVariantAnalysisFromCommand.bind(this), + "codeQL.runVariantAnalysisContextExplorer": createMultiSelectionCommand( + this.runVariantAnalysisFromExplorer.bind(this), + ), "codeQLQueries.runVariantAnalysisContextMenu": this.runVariantAnalysisFromQueriesPanel.bind(this), }; @@ -194,6 +197,13 @@ export class VariantAnalysisManager ); } + private async runVariantAnalysisFromExplorer(fileURIs: Uri[]): Promise { + if (fileURIs.length !== 1) { + throw new Error("Can only run a single query at a time"); + } + return this.runVariantAnalysisFromCommand(fileURIs[0]); + } + private async runVariantAnalysisFromQueriesPanel( queryTreeViewItem: QueryTreeViewItem, ): Promise {