Skip to content

Commit a9e4951

Browse files
Convert extensions/ql-vscode/src/query-history/query-history-manager.ts to call typed commands
1 parent 2e7952c commit a9e4951

6 files changed

Lines changed: 15 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type BuiltInVsCodeCommands = {
3838
// The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view
3939
"codeQLDatabases.focus": () => Promise<void>;
4040
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
41+
revealFileInOS: (uri: Uri) => Promise<void>;
4142
setContext: (
4243
key: `${"codeql" | "codeQL"}${string}`,
4344
value: unknown,

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ async function activateWithInstalledDistribution(
777777
};
778778

779779
const qhm = new QueryHistoryManager(
780+
app,
780781
qs,
781782
dbm,
782783
localQueryResultsView,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { join, dirname } from "path";
22
import {
3-
commands,
43
Disposable,
54
env,
65
EventEmitter,
@@ -61,6 +60,7 @@ import { HistoryTreeDataProvider } from "./history-tree-data-provider";
6160
import { redactableError } from "../pure/errors";
6261
import { QueryHistoryDirs } from "./query-history-dirs";
6362
import { QueryHistoryCommands } from "../common/commands";
63+
import { App } from "../common/app";
6464
import { tryOpenExternalFile } from "../vscode-utils/external-files";
6565

6666
/**
@@ -131,6 +131,7 @@ export class QueryHistoryManager extends DisposableObject {
131131
readonly onDidCompleteQuery = this._onDidCompleteQuery.event;
132132

133133
constructor(
134+
private readonly app: App,
134135
private readonly qs: QueryRunner,
135136
private readonly dbm: DatabaseManager,
136137
private readonly localQueriesResultsView: ResultsView,
@@ -747,7 +748,7 @@ export class QueryHistoryManager extends DisposableObject {
747748
}
748749
}
749750
try {
750-
await commands.executeCommand(
751+
await this.app.commands.execute(
751752
"revealFileInOS",
752753
Uri.file(externalFilePath),
753754
);
@@ -1073,7 +1074,7 @@ export class QueryHistoryManager extends DisposableObject {
10731074

10741075
const actionsWorkflowRunUrl = getActionsWorkflowRunUrl(finalSingleItem);
10751076

1076-
await commands.executeCommand(
1077+
await this.app.commands.execute(
10771078
"vscode.open",
10781079
Uri.parse(actionsWorkflowRunUrl),
10791080
);
@@ -1097,7 +1098,7 @@ export class QueryHistoryManager extends DisposableObject {
10971098
return;
10981099
}
10991100

1100-
await commands.executeCommand(
1101+
await this.app.commands.execute(
11011102
"codeQL.copyVariantAnalysisRepoList",
11021103
finalSingleItem.variantAnalysis.id,
11031104
);

extensions/ql-vscode/test/vscode-tests/no-workspace/query-history/history-tree-data-provider.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from "../../../../src/query-history/history-tree-data-provider";
2828
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
2929
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
30+
import { createMockApp } from "../../../__mocks__/appMock";
3031

3132
describe("HistoryTreeDataProvider", () => {
3233
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
@@ -421,6 +422,7 @@ describe("HistoryTreeDataProvider", () => {
421422

422423
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
423424
const qhm = new QueryHistoryManager(
425+
createMockApp({}),
424426
{} as QueryRunner,
425427
{} as DatabaseManager,
426428
localQueriesResultsViewStub,

extensions/ql-vscode/test/vscode-tests/no-workspace/query-history/query-history-manager.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,15 +777,15 @@ describe("QueryHistoryManager", () => {
777777
const item = localQueryHistory[4];
778778
await queryHistoryManager.handleCopyRepoList(item, [item]);
779779

780-
expect(executeCommandSpy).not.toBeCalled();
780+
expect(executeCommand).not.toBeCalled();
781781
});
782782

783783
it("should copy repo list for a single variant analysis", async () => {
784784
queryHistoryManager = await createMockQueryHistory(allHistory);
785785

786786
const item = variantAnalysisHistory[1];
787787
await queryHistoryManager.handleCopyRepoList(item, [item]);
788-
expect(executeCommandSpy).toBeCalledWith(
788+
expect(executeCommand).toBeCalledWith(
789789
"codeQL.copyVariantAnalysisRepoList",
790790
item.variantAnalysis.id,
791791
);
@@ -797,7 +797,7 @@ describe("QueryHistoryManager", () => {
797797
const item1 = variantAnalysisHistory[1];
798798
const item2 = variantAnalysisHistory[3];
799799
await queryHistoryManager.handleCopyRepoList(item1, [item1, item2]);
800-
expect(executeCommandSpy).not.toBeCalled();
800+
expect(executeCommand).not.toBeCalled();
801801
});
802802
});
803803

@@ -1094,6 +1094,7 @@ describe("QueryHistoryManager", () => {
10941094

10951095
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
10961096
const qhm = new QueryHistoryManager(
1097+
mockApp,
10971098
{} as QueryRunner,
10981099
{} as DatabaseManager,
10991100
localQueriesResultsViewStub,

extensions/ql-vscode/test/vscode-tests/no-workspace/query-history/variant-analysis-history.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { VariantAnalysisManager } from "../../../../src/variant-analysis/variant
2121
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
2222
import { mockedObject } from "../../utils/mocking.helpers";
2323
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
24+
import { createMockApp } from "../../../__mocks__/appMock";
2425

2526
// set a higher timeout since recursive delete may take a while, expecially on Windows.
2627
jest.setTimeout(120000);
@@ -73,6 +74,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
7374
).queries;
7475

7576
qhm = new QueryHistoryManager(
77+
createMockApp({}),
7678
{} as QueryRunner,
7779
{} as DatabaseManager,
7880
localQueriesResultsViewStub,

0 commit comments

Comments
 (0)