Skip to content

Commit 9f85f56

Browse files
committed
Convert test UI commands to typed commands
1 parent 88a9ecb commit 9f85f56

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
55
import type { DatabaseItem } from "../local-databases";
66
import type { QueryHistoryInfo } from "../query-history/query-history-info";
77
import type { RepositoriesFilterSortStateWithIds } from "../pure/variant-analysis-filter-sort";
8+
import type { TestTreeNode } from "../test-tree-node";
89
import type {
910
VariantAnalysis,
1011
VariantAnalysisScannedRepository,
@@ -195,6 +196,11 @@ export type SummaryLanguageSupportCommands = {
195196
"codeQL.gotoQL": () => Promise<void>;
196197
};
197198

199+
export type TestUICommands = {
200+
"codeQLTests.showOutputDifferences": (node: TestTreeNode) => Promise<void>;
201+
"codeQLTests.acceptOutput": (node: TestTreeNode) => Promise<void>;
202+
};
203+
198204
export type AllCommands = BaseCommands &
199205
QueryHistoryCommands &
200206
LocalDatabasesCommands &
@@ -204,7 +210,8 @@ export type AllCommands = BaseCommands &
204210
AstViewerCommands &
205211
PackagingCommands &
206212
EvalLogViewerCommands &
207-
SummaryLanguageSupportCommands;
213+
SummaryLanguageSupportCommands &
214+
Partial<TestUICommands>;
208215

209216
export type AppCommandManager = CommandManager<AllCommands>;
210217

extensions/ql-vscode/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import {
115115
AllCommands,
116116
BaseCommands,
117117
QueryServerCommands,
118+
TestUICommands,
118119
} from "./common/commands";
119120
import {
120121
getLocalQueryCommands,
@@ -795,6 +796,7 @@ async function activateWithInstalledDistribution(
795796
const testExplorerExtension = extensions.getExtension<TestHub>(
796797
testExplorerExtensionId,
797798
);
799+
let testUiCommands: Partial<TestUICommands> = {};
798800
if (testExplorerExtension) {
799801
const testHub = testExplorerExtension.exports;
800802
const testAdapterFactory = new QLTestAdapterFactory(
@@ -806,6 +808,8 @@ async function activateWithInstalledDistribution(
806808

807809
const testUIService = new TestUIService(testHub);
808810
ctx.subscriptions.push(testUIService);
811+
812+
testUiCommands = testUIService.getCommands();
809813
}
810814

811815
const astViewer = new AstViewer();
@@ -846,6 +850,7 @@ async function activateWithInstalledDistribution(
846850
}),
847851
...evalLogViewer.getCommands(),
848852
...summaryLanguageSupport.getCommands(),
853+
...testUiCommands,
849854
};
850855

851856
for (const [commandName, command] of Object.entries(allCommands)) {

extensions/ql-vscode/src/test-ui.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { TestTreeNode } from "./test-tree-node";
1616
import { DisposableObject } from "./pure/disposable-object";
1717
import { UIService } from "./vscode-utils/ui-service";
1818
import { QLTestAdapter, getExpectedFile, getActualFile } from "./test-adapter";
19-
import { extLogger } from "./common";
19+
import { TestUICommands } from "./common/commands";
2020

2121
type VSCodeTestEvent =
2222
| TestRunStartedEvent
@@ -48,16 +48,17 @@ export class TestUIService extends UIService implements TestController {
4848
constructor(private readonly testHub: TestHub) {
4949
super();
5050

51-
void extLogger.log("Registering CodeQL test panel commands.");
52-
this.registerCommand(
53-
"codeQLTests.showOutputDifferences",
54-
this.showOutputDifferences,
55-
);
56-
this.registerCommand("codeQLTests.acceptOutput", this.acceptOutput);
57-
5851
testHub.registerTestController(this);
5952
}
6053

54+
public getCommands(): TestUICommands {
55+
return {
56+
"codeQLTests.showOutputDifferences":
57+
this.showOutputDifferences.bind(this),
58+
"codeQLTests.acceptOutput": this.acceptOutput.bind(this),
59+
};
60+
}
61+
6162
public dispose(): void {
6263
this.testHub.unregisterTestController(this);
6364

0 commit comments

Comments
 (0)