diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index f35d28e36..9d3afca17 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -644,7 +644,7 @@ }, { "command": "codeQLQueryHistory.openOnGithub", - "title": "View Logs" + "title": "Open on GitHub" }, { "command": "codeQLQueryHistory.copyRepoList", diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index df9a653fa..dcd175df0 100644 --- a/extensions/ql-vscode/src/common/commands.ts +++ b/extensions/ql-vscode/src/common/commands.ts @@ -1,5 +1,13 @@ -import { CommandManager } from "../packages/commands"; +import type { CommandManager } from "../packages/commands"; import type { Uri } from "vscode"; +import type { QueryHistoryInfo } from "../query-history/query-history-info"; + +// A command function matching the signature that VS Code calls when +// a command on a selection is invoked. +export type SelectionCommandFunction = ( + singleItem: Item, + multiSelect: Item[], +) => Promise; /** * Contains type definitions for all commands used by the extension. @@ -13,6 +21,38 @@ export type BaseCommands = { "codeQL.openDocumentation": () => Promise; }; +// Commands used for the query history panel +export type QueryHistoryCommands = { + // Commands in the "navigation" group + "codeQLQueryHistory.sortByName": () => Promise; + "codeQLQueryHistory.sortByDate": () => Promise; + "codeQLQueryHistory.sortByCount": () => Promise; + + // Commands in the context menu or in the hover menu + "codeQLQueryHistory.openQueryTitleMenu": SelectionCommandFunction; + "codeQLQueryHistory.openQueryContextMenu": SelectionCommandFunction; + "codeQLQueryHistory.removeHistoryItemTitleMenu": SelectionCommandFunction; + "codeQLQueryHistory.removeHistoryItemContextMenu": SelectionCommandFunction; + "codeQLQueryHistory.removeHistoryItemContextInline": SelectionCommandFunction; + "codeQLQueryHistory.renameItem": SelectionCommandFunction; + "codeQLQueryHistory.compareWith": SelectionCommandFunction; + "codeQLQueryHistory.showEvalLog": SelectionCommandFunction; + "codeQLQueryHistory.showEvalLogSummary": SelectionCommandFunction; + "codeQLQueryHistory.showEvalLogViewer": SelectionCommandFunction; + "codeQLQueryHistory.showQueryLog": SelectionCommandFunction; + "codeQLQueryHistory.showQueryText": SelectionCommandFunction; + "codeQLQueryHistory.openQueryDirectory": SelectionCommandFunction; + "codeQLQueryHistory.cancel": SelectionCommandFunction; + "codeQLQueryHistory.exportResults": SelectionCommandFunction; + "codeQLQueryHistory.viewCsvResults": SelectionCommandFunction; + "codeQLQueryHistory.viewCsvAlerts": SelectionCommandFunction; + "codeQLQueryHistory.viewSarifAlerts": SelectionCommandFunction; + "codeQLQueryHistory.viewDil": SelectionCommandFunction; + "codeQLQueryHistory.itemClicked": SelectionCommandFunction; + "codeQLQueryHistory.openOnGithub": SelectionCommandFunction; + "codeQLQueryHistory.copyRepoList": SelectionCommandFunction; +}; + // Commands tied to variant analysis export type VariantAnalysisCommands = { "codeQL.openVariantAnalysisLogs": ( @@ -22,6 +62,8 @@ export type VariantAnalysisCommands = { "codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise; }; -export type AllCommands = BaseCommands & VariantAnalysisCommands; +export type AllCommands = BaseCommands & + QueryHistoryCommands & + VariantAnalysisCommands; export type AppCommandManager = CommandManager; diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 5225e2deb..27beb7b32 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -1094,6 +1094,7 @@ async function activateWithInstalledDistribution( const allCommands: AllCommands = { ...getCommands(), + ...qhm.getCommands(), ...variantAnalysisManager.getCommands(), }; diff --git a/extensions/ql-vscode/src/query-history/query-history-manager.ts b/extensions/ql-vscode/src/query-history/query-history-manager.ts index 14e5ec8ea..46f938848 100644 --- a/extensions/ql-vscode/src/query-history/query-history-manager.ts +++ b/extensions/ql-vscode/src/query-history/query-history-manager.ts @@ -25,7 +25,6 @@ import { import { extLogger } from "../common"; import { URLSearchParams } from "url"; import { DisposableObject } from "../pure/disposable-object"; -import { commandRunner } from "../commandRunner"; import { ONE_HOUR_IN_MS, TWO_HOURS_IN_MS } from "../pure/time"; import { asError, @@ -66,6 +65,7 @@ import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis import { HistoryTreeDataProvider } from "./history-tree-data-provider"; import { redactableError } from "../pure/errors"; import { QueryHistoryDirs } from "./query-history-dirs"; +import { QueryHistoryCommands } from "../common/commands"; /** * query-history-manager.ts @@ -201,159 +201,6 @@ export class QueryHistoryManager extends DisposableObject { }), ); - void extLogger.log("Registering query history panel commands."); - this.push( - commandRunner( - "codeQLQueryHistory.openQueryTitleMenu", - this.handleOpenQuery.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.openQueryContextMenu", - this.handleOpenQuery.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.removeHistoryItemTitleMenu", - this.handleRemoveHistoryItem.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.removeHistoryItemContextMenu", - this.handleRemoveHistoryItem.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.removeHistoryItemContextInline", - this.handleRemoveHistoryItem.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.sortByName", - this.handleSortByName.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.sortByDate", - this.handleSortByDate.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.sortByCount", - this.handleSortByCount.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.renameItem", - this.handleRenameItem.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.compareWith", - this.handleCompareWith.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.showQueryLog", - this.handleShowQueryLog.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.openQueryDirectory", - this.handleOpenQueryDirectory.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.showEvalLog", - this.handleShowEvalLog.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.showEvalLogSummary", - this.handleShowEvalLogSummary.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.showEvalLogViewer", - this.handleShowEvalLogViewer.bind(this), - ), - ); - this.push( - commandRunner("codeQLQueryHistory.cancel", this.handleCancel.bind(this)), - ); - this.push( - commandRunner( - "codeQLQueryHistory.showQueryText", - this.handleShowQueryText.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.exportResults", - this.handleExportResults.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.viewCsvResults", - this.handleViewCsvResults.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.viewCsvAlerts", - this.handleViewCsvAlerts.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.viewSarifAlerts", - this.handleViewSarifAlerts.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.viewDil", - this.handleViewDil.bind(this), - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.itemClicked", - async (item: LocalQueryInfo) => { - return this.handleItemClicked(item, [item]); - }, - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.openOnGithub", - async (item: LocalQueryInfo) => { - return this.handleOpenOnGithub(item, [item]); - }, - ), - ); - this.push( - commandRunner( - "codeQLQueryHistory.copyRepoList", - this.handleCopyRepoList.bind(this), - ), - ); - // There are two configuration items that affect the query history: // 1. The ttl for query history items. // 2. The default label for query history items. @@ -388,6 +235,45 @@ export class QueryHistoryManager extends DisposableObject { this.registerToVariantAnalysisEvents(); } + public getCommands(): QueryHistoryCommands { + return { + "codeQLQueryHistory.sortByName": this.handleSortByName.bind(this), + "codeQLQueryHistory.sortByDate": this.handleSortByDate.bind(this), + "codeQLQueryHistory.sortByCount": this.handleSortByCount.bind(this), + + "codeQLQueryHistory.openQueryTitleMenu": this.handleOpenQuery.bind(this), + "codeQLQueryHistory.openQueryContextMenu": + this.handleOpenQuery.bind(this), + "codeQLQueryHistory.removeHistoryItemTitleMenu": + this.handleRemoveHistoryItem.bind(this), + "codeQLQueryHistory.removeHistoryItemContextMenu": + this.handleRemoveHistoryItem.bind(this), + "codeQLQueryHistory.removeHistoryItemContextInline": + this.handleRemoveHistoryItem.bind(this), + "codeQLQueryHistory.renameItem": this.handleRenameItem.bind(this), + "codeQLQueryHistory.compareWith": this.handleCompareWith.bind(this), + "codeQLQueryHistory.showEvalLog": this.handleShowEvalLog.bind(this), + "codeQLQueryHistory.showEvalLogSummary": + this.handleShowEvalLogSummary.bind(this), + "codeQLQueryHistory.showEvalLogViewer": + this.handleShowEvalLogViewer.bind(this), + "codeQLQueryHistory.showQueryLog": this.handleShowQueryLog.bind(this), + "codeQLQueryHistory.showQueryText": this.handleShowQueryText.bind(this), + "codeQLQueryHistory.openQueryDirectory": + this.handleOpenQueryDirectory.bind(this), + "codeQLQueryHistory.cancel": this.handleCancel.bind(this), + "codeQLQueryHistory.exportResults": this.handleExportResults.bind(this), + "codeQLQueryHistory.viewCsvResults": this.handleViewCsvResults.bind(this), + "codeQLQueryHistory.viewCsvAlerts": this.handleViewCsvAlerts.bind(this), + "codeQLQueryHistory.viewSarifAlerts": + this.handleViewSarifAlerts.bind(this), + "codeQLQueryHistory.viewDil": this.handleViewDil.bind(this), + "codeQLQueryHistory.itemClicked": this.handleItemClicked.bind(this), + "codeQLQueryHistory.openOnGithub": this.handleOpenOnGithub.bind(this), + "codeQLQueryHistory.copyRepoList": this.handleCopyRepoList.bind(this), + }; + } + public completeQuery(info: LocalQueryInfo, results: QueryWithResults): void { info.completeThisQuery(results); this._onDidCompleteQuery.fire(info);