Skip to content

Commit 322c1a8

Browse files
authored
Merge pull request #2206 from github/koesie10/test-ui-typed-commands
Convert test UI commands to typed commands
2 parents 125af11 + 59378da commit 322c1a8

File tree

5 files changed

+24
-44
lines changed

5 files changed

+24
-44
lines changed

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

Lines changed: 7 additions & 0 deletions
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,
@@ -204,6 +205,11 @@ export type SummaryLanguageSupportCommands = {
204205
"codeQL.gotoQL": () => Promise<void>;
205206
};
206207

208+
export type TestUICommands = {
209+
"codeQLTests.showOutputDifferences": (node: TestTreeNode) => Promise<void>;
210+
"codeQLTests.acceptOutput": (node: TestTreeNode) => Promise<void>;
211+
};
212+
207213
export type MockGitHubApiServerCommands = {
208214
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
209215
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
@@ -223,6 +229,7 @@ export type AllCommands = BaseCommands &
223229
PackagingCommands &
224230
EvalLogViewerCommands &
225231
SummaryLanguageSupportCommands &
232+
Partial<TestUICommands> &
226233
MockGitHubApiServerCommands;
227234

228235
export type AppCommandManager = CommandManager<AllCommands>;

extensions/ql-vscode/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ import {
116116
AllCommands,
117117
BaseCommands,
118118
QueryServerCommands,
119+
TestUICommands,
119120
} from "./common/commands";
120121
import {
121122
getLocalQueryCommands,
@@ -796,6 +797,7 @@ async function activateWithInstalledDistribution(
796797
const testExplorerExtension = extensions.getExtension<TestHub>(
797798
testExplorerExtensionId,
798799
);
800+
let testUiCommands: Partial<TestUICommands> = {};
799801
if (testExplorerExtension) {
800802
const testHub = testExplorerExtension.exports;
801803
const testAdapterFactory = new QLTestAdapterFactory(
@@ -807,6 +809,8 @@ async function activateWithInstalledDistribution(
807809

808810
const testUIService = new TestUIService(testHub);
809811
ctx.subscriptions.push(testUIService);
812+
813+
testUiCommands = testUIService.getCommands();
810814
}
811815

812816
const astViewer = new AstViewer();
@@ -851,6 +855,7 @@ async function activateWithInstalledDistribution(
851855
}),
852856
...evalLogViewer.getCommands(),
853857
...summaryLanguageSupport.getCommands(),
858+
...testUiCommands,
854859
...mockServer.getCommands(),
855860
};
856861

extensions/ql-vscode/src/packages/commands/CommandManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CommandManager<
3030
constructor(
3131
private readonly commandRegister: <T extends CommandName>(
3232
commandName: T,
33-
fn: Commands[T],
33+
fn: NonNullable<Commands[T]>,
3434
) => Disposable,
3535
private readonly commandExecute: <T extends CommandName>(
3636
commandName: T,
@@ -43,7 +43,7 @@ export class CommandManager<
4343
*/
4444
register<T extends CommandName>(
4545
commandName: T,
46-
definition: Commands[T],
46+
definition: NonNullable<Commands[T]>,
4747
): void {
4848
this.commands.push(this.commandRegister(commandName, definition));
4949
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {
1414
import { showAndLogWarningMessage } from "./helpers";
1515
import { TestTreeNode } from "./test-tree-node";
1616
import { DisposableObject } from "./pure/disposable-object";
17-
import { UIService } from "./vscode-utils/ui-service";
1817
import { QLTestAdapter, getExpectedFile, getActualFile } from "./test-adapter";
19-
import { extLogger } from "./common";
18+
import { TestUICommands } from "./common/commands";
2019

2120
type VSCodeTestEvent =
2221
| TestRunStartedEvent
@@ -42,22 +41,23 @@ class QLTestListener extends DisposableObject {
4241
/**
4342
* Service that implements all UI and commands for QL tests.
4443
*/
45-
export class TestUIService extends UIService implements TestController {
44+
export class TestUIService extends DisposableObject implements TestController {
4645
private readonly listeners: Map<TestAdapter, QLTestListener> = new Map();
4746

4847
constructor(private readonly testHub: TestHub) {
4948
super();
5049

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-
5850
testHub.registerTestController(this);
5951
}
6052

53+
public getCommands(): TestUICommands {
54+
return {
55+
"codeQLTests.showOutputDifferences":
56+
this.showOutputDifferences.bind(this),
57+
"codeQLTests.acceptOutput": this.acceptOutput.bind(this),
58+
};
59+
}
60+
6161
public dispose(): void {
6262
this.testHub.unregisterTestController(this);
6363

extensions/ql-vscode/src/vscode-utils/ui-service.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)