Skip to content

Commit f86c0b8

Browse files
authored
Merge pull request #2176 from github/koesie10/query-history-commands-typed
Convert query history commands to typed commands
2 parents 7914403 + 5be08d7 commit f86c0b8

File tree

3 files changed

+85
-156
lines changed

3 files changed

+85
-156
lines changed

extensions/ql-vscode/src/common/commands.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { CommandManager } from "../packages/commands";
1+
import type { CommandManager } from "../packages/commands";
22
import type { Uri } from "vscode";
3+
import type { QueryHistoryInfo } from "../query-history/query-history-info";
4+
5+
// A command function matching the signature that VS Code calls when
6+
// a command on a selection is invoked.
7+
export type SelectionCommandFunction<Item> = (
8+
singleItem: Item,
9+
multiSelect: Item[],
10+
) => Promise<void>;
311

412
/**
513
* Contains type definitions for all commands used by the extension.
@@ -13,6 +21,38 @@ export type BaseCommands = {
1321
"codeQL.openDocumentation": () => Promise<void>;
1422
};
1523

24+
// Commands used for the query history panel
25+
export type QueryHistoryCommands = {
26+
// Commands in the "navigation" group
27+
"codeQLQueryHistory.sortByName": () => Promise<void>;
28+
"codeQLQueryHistory.sortByDate": () => Promise<void>;
29+
"codeQLQueryHistory.sortByCount": () => Promise<void>;
30+
31+
// Commands in the context menu or in the hover menu
32+
"codeQLQueryHistory.openQueryTitleMenu": SelectionCommandFunction<QueryHistoryInfo>;
33+
"codeQLQueryHistory.openQueryContextMenu": SelectionCommandFunction<QueryHistoryInfo>;
34+
"codeQLQueryHistory.removeHistoryItemTitleMenu": SelectionCommandFunction<QueryHistoryInfo>;
35+
"codeQLQueryHistory.removeHistoryItemContextMenu": SelectionCommandFunction<QueryHistoryInfo>;
36+
"codeQLQueryHistory.removeHistoryItemContextInline": SelectionCommandFunction<QueryHistoryInfo>;
37+
"codeQLQueryHistory.renameItem": SelectionCommandFunction<QueryHistoryInfo>;
38+
"codeQLQueryHistory.compareWith": SelectionCommandFunction<QueryHistoryInfo>;
39+
"codeQLQueryHistory.showEvalLog": SelectionCommandFunction<QueryHistoryInfo>;
40+
"codeQLQueryHistory.showEvalLogSummary": SelectionCommandFunction<QueryHistoryInfo>;
41+
"codeQLQueryHistory.showEvalLogViewer": SelectionCommandFunction<QueryHistoryInfo>;
42+
"codeQLQueryHistory.showQueryLog": SelectionCommandFunction<QueryHistoryInfo>;
43+
"codeQLQueryHistory.showQueryText": SelectionCommandFunction<QueryHistoryInfo>;
44+
"codeQLQueryHistory.openQueryDirectory": SelectionCommandFunction<QueryHistoryInfo>;
45+
"codeQLQueryHistory.cancel": SelectionCommandFunction<QueryHistoryInfo>;
46+
"codeQLQueryHistory.exportResults": SelectionCommandFunction<QueryHistoryInfo>;
47+
"codeQLQueryHistory.viewCsvResults": SelectionCommandFunction<QueryHistoryInfo>;
48+
"codeQLQueryHistory.viewCsvAlerts": SelectionCommandFunction<QueryHistoryInfo>;
49+
"codeQLQueryHistory.viewSarifAlerts": SelectionCommandFunction<QueryHistoryInfo>;
50+
"codeQLQueryHistory.viewDil": SelectionCommandFunction<QueryHistoryInfo>;
51+
"codeQLQueryHistory.itemClicked": SelectionCommandFunction<QueryHistoryInfo>;
52+
"codeQLQueryHistory.openOnGithub": SelectionCommandFunction<QueryHistoryInfo>;
53+
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
54+
};
55+
1656
// Commands tied to variant analysis
1757
export type VariantAnalysisCommands = {
1858
"codeQL.openVariantAnalysisLogs": (
@@ -22,6 +62,8 @@ export type VariantAnalysisCommands = {
2262
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
2363
};
2464

25-
export type AllCommands = BaseCommands & VariantAnalysisCommands;
65+
export type AllCommands = BaseCommands &
66+
QueryHistoryCommands &
67+
VariantAnalysisCommands;
2668

2769
export type AppCommandManager = CommandManager<AllCommands>;

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@ async function activateWithInstalledDistribution(
10941094

10951095
const allCommands: AllCommands = {
10961096
...getCommands(),
1097+
...qhm.getCommands(),
10971098
...variantAnalysisManager.getCommands(),
10981099
};
10991100

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 40 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
import { extLogger } from "../common";
2626
import { URLSearchParams } from "url";
2727
import { DisposableObject } from "../pure/disposable-object";
28-
import { commandRunner } from "../commandRunner";
2928
import { ONE_HOUR_IN_MS, TWO_HOURS_IN_MS } from "../pure/time";
3029
import {
3130
asError,
@@ -66,6 +65,7 @@ import { getTotalResultCount } from "../variant-analysis/shared/variant-analysis
6665
import { HistoryTreeDataProvider } from "./history-tree-data-provider";
6766
import { redactableError } from "../pure/errors";
6867
import { QueryHistoryDirs } from "./query-history-dirs";
68+
import { QueryHistoryCommands } from "../common/commands";
6969

7070
/**
7171
* query-history-manager.ts
@@ -201,159 +201,6 @@ export class QueryHistoryManager extends DisposableObject {
201201
}),
202202
);
203203

204-
void extLogger.log("Registering query history panel commands.");
205-
this.push(
206-
commandRunner(
207-
"codeQLQueryHistory.openQueryTitleMenu",
208-
this.handleOpenQuery.bind(this),
209-
),
210-
);
211-
this.push(
212-
commandRunner(
213-
"codeQLQueryHistory.openQueryContextMenu",
214-
this.handleOpenQuery.bind(this),
215-
),
216-
);
217-
this.push(
218-
commandRunner(
219-
"codeQLQueryHistory.removeHistoryItemTitleMenu",
220-
this.handleRemoveHistoryItem.bind(this),
221-
),
222-
);
223-
this.push(
224-
commandRunner(
225-
"codeQLQueryHistory.removeHistoryItemContextMenu",
226-
this.handleRemoveHistoryItem.bind(this),
227-
),
228-
);
229-
this.push(
230-
commandRunner(
231-
"codeQLQueryHistory.removeHistoryItemContextInline",
232-
this.handleRemoveHistoryItem.bind(this),
233-
),
234-
);
235-
this.push(
236-
commandRunner(
237-
"codeQLQueryHistory.sortByName",
238-
this.handleSortByName.bind(this),
239-
),
240-
);
241-
this.push(
242-
commandRunner(
243-
"codeQLQueryHistory.sortByDate",
244-
this.handleSortByDate.bind(this),
245-
),
246-
);
247-
this.push(
248-
commandRunner(
249-
"codeQLQueryHistory.sortByCount",
250-
this.handleSortByCount.bind(this),
251-
),
252-
);
253-
this.push(
254-
commandRunner(
255-
"codeQLQueryHistory.renameItem",
256-
this.handleRenameItem.bind(this),
257-
),
258-
);
259-
this.push(
260-
commandRunner(
261-
"codeQLQueryHistory.compareWith",
262-
this.handleCompareWith.bind(this),
263-
),
264-
);
265-
this.push(
266-
commandRunner(
267-
"codeQLQueryHistory.showQueryLog",
268-
this.handleShowQueryLog.bind(this),
269-
),
270-
);
271-
this.push(
272-
commandRunner(
273-
"codeQLQueryHistory.openQueryDirectory",
274-
this.handleOpenQueryDirectory.bind(this),
275-
),
276-
);
277-
this.push(
278-
commandRunner(
279-
"codeQLQueryHistory.showEvalLog",
280-
this.handleShowEvalLog.bind(this),
281-
),
282-
);
283-
this.push(
284-
commandRunner(
285-
"codeQLQueryHistory.showEvalLogSummary",
286-
this.handleShowEvalLogSummary.bind(this),
287-
),
288-
);
289-
this.push(
290-
commandRunner(
291-
"codeQLQueryHistory.showEvalLogViewer",
292-
this.handleShowEvalLogViewer.bind(this),
293-
),
294-
);
295-
this.push(
296-
commandRunner("codeQLQueryHistory.cancel", this.handleCancel.bind(this)),
297-
);
298-
this.push(
299-
commandRunner(
300-
"codeQLQueryHistory.showQueryText",
301-
this.handleShowQueryText.bind(this),
302-
),
303-
);
304-
this.push(
305-
commandRunner(
306-
"codeQLQueryHistory.exportResults",
307-
this.handleExportResults.bind(this),
308-
),
309-
);
310-
this.push(
311-
commandRunner(
312-
"codeQLQueryHistory.viewCsvResults",
313-
this.handleViewCsvResults.bind(this),
314-
),
315-
);
316-
this.push(
317-
commandRunner(
318-
"codeQLQueryHistory.viewCsvAlerts",
319-
this.handleViewCsvAlerts.bind(this),
320-
),
321-
);
322-
this.push(
323-
commandRunner(
324-
"codeQLQueryHistory.viewSarifAlerts",
325-
this.handleViewSarifAlerts.bind(this),
326-
),
327-
);
328-
this.push(
329-
commandRunner(
330-
"codeQLQueryHistory.viewDil",
331-
this.handleViewDil.bind(this),
332-
),
333-
);
334-
this.push(
335-
commandRunner(
336-
"codeQLQueryHistory.itemClicked",
337-
async (item: LocalQueryInfo) => {
338-
return this.handleItemClicked(item, [item]);
339-
},
340-
),
341-
);
342-
this.push(
343-
commandRunner(
344-
"codeQLQueryHistory.openOnGithub",
345-
async (item: LocalQueryInfo) => {
346-
return this.handleOpenOnGithub(item, [item]);
347-
},
348-
),
349-
);
350-
this.push(
351-
commandRunner(
352-
"codeQLQueryHistory.copyRepoList",
353-
this.handleCopyRepoList.bind(this),
354-
),
355-
);
356-
357204
// There are two configuration items that affect the query history:
358205
// 1. The ttl for query history items.
359206
// 2. The default label for query history items.
@@ -388,6 +235,45 @@ export class QueryHistoryManager extends DisposableObject {
388235
this.registerToVariantAnalysisEvents();
389236
}
390237

238+
public getCommands(): QueryHistoryCommands {
239+
return {
240+
"codeQLQueryHistory.sortByName": this.handleSortByName.bind(this),
241+
"codeQLQueryHistory.sortByDate": this.handleSortByDate.bind(this),
242+
"codeQLQueryHistory.sortByCount": this.handleSortByCount.bind(this),
243+
244+
"codeQLQueryHistory.openQueryTitleMenu": this.handleOpenQuery.bind(this),
245+
"codeQLQueryHistory.openQueryContextMenu":
246+
this.handleOpenQuery.bind(this),
247+
"codeQLQueryHistory.removeHistoryItemTitleMenu":
248+
this.handleRemoveHistoryItem.bind(this),
249+
"codeQLQueryHistory.removeHistoryItemContextMenu":
250+
this.handleRemoveHistoryItem.bind(this),
251+
"codeQLQueryHistory.removeHistoryItemContextInline":
252+
this.handleRemoveHistoryItem.bind(this),
253+
"codeQLQueryHistory.renameItem": this.handleRenameItem.bind(this),
254+
"codeQLQueryHistory.compareWith": this.handleCompareWith.bind(this),
255+
"codeQLQueryHistory.showEvalLog": this.handleShowEvalLog.bind(this),
256+
"codeQLQueryHistory.showEvalLogSummary":
257+
this.handleShowEvalLogSummary.bind(this),
258+
"codeQLQueryHistory.showEvalLogViewer":
259+
this.handleShowEvalLogViewer.bind(this),
260+
"codeQLQueryHistory.showQueryLog": this.handleShowQueryLog.bind(this),
261+
"codeQLQueryHistory.showQueryText": this.handleShowQueryText.bind(this),
262+
"codeQLQueryHistory.openQueryDirectory":
263+
this.handleOpenQueryDirectory.bind(this),
264+
"codeQLQueryHistory.cancel": this.handleCancel.bind(this),
265+
"codeQLQueryHistory.exportResults": this.handleExportResults.bind(this),
266+
"codeQLQueryHistory.viewCsvResults": this.handleViewCsvResults.bind(this),
267+
"codeQLQueryHistory.viewCsvAlerts": this.handleViewCsvAlerts.bind(this),
268+
"codeQLQueryHistory.viewSarifAlerts":
269+
this.handleViewSarifAlerts.bind(this),
270+
"codeQLQueryHistory.viewDil": this.handleViewDil.bind(this),
271+
"codeQLQueryHistory.itemClicked": this.handleItemClicked.bind(this),
272+
"codeQLQueryHistory.openOnGithub": this.handleOpenOnGithub.bind(this),
273+
"codeQLQueryHistory.copyRepoList": this.handleCopyRepoList.bind(this),
274+
};
275+
}
276+
391277
public completeQuery(info: LocalQueryInfo, results: QueryWithResults): void {
392278
info.completeThisQuery(results);
393279
this._onDidCompleteQuery.fire(info);

0 commit comments

Comments
 (0)