Skip to content

Commit a3c4c8f

Browse files
Merge pull request #2212 from github/robertbrignull/app_executeCommand
Replace app.executeCommand with app.commands.execute
2 parents 73b0a05 + 8fbde9f commit a3c4c8f

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AppCommandManager } from "./commands";
77

88
export interface App {
99
createEventEmitter<T>(): AppEventEmitter<T>;
10-
executeCommand(command: string, ...args: any): Thenable<void>;
1110
readonly mode: AppMode;
1211
readonly logger: Logger;
1312
readonly subscriptions: Disposable[];

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

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export type SingleSelectionCommandFunction<Item> = (
3636
// See https://code.visualstudio.com/api/references/commands
3737
export type BuiltInVsCodeCommands = {
3838
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
39+
setContext: (
40+
key: `${"codeql" | "codeQL"}${string}`,
41+
value: unknown,
42+
) => Promise<void>;
3943
"workbench.action.reloadWindow": () => Promise<void>;
4044
};
4145

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

-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,4 @@ export class ExtensionApp implements App {
6161
public createEventEmitter<T>(): AppEventEmitter<T> {
6262
return new VSCodeAppEventEmitter<T>();
6363
}
64-
65-
public executeCommand(command: string, ...args: any): Thenable<void> {
66-
return vscode.commands.executeCommand(command, ...args);
67-
}
6864
}

extensions/ql-vscode/src/databases/config/db-config-store.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ export class DbConfigStore extends DisposableObject {
391391

392392
if (this.configErrors.length === 0) {
393393
this.config = newConfig;
394-
await this.app.executeCommand(
394+
await this.app.commands.execute(
395395
"setContext",
396396
"codeQLVariantAnalysisRepositories.configError",
397397
false,
398398
);
399399
} else {
400400
this.config = undefined;
401-
await this.app.executeCommand(
401+
await this.app.commands.execute(
402402
"setContext",
403403
"codeQLVariantAnalysisRepositories.configError",
404404
true,
@@ -426,14 +426,14 @@ export class DbConfigStore extends DisposableObject {
426426

427427
if (this.configErrors.length === 0) {
428428
this.config = newConfig;
429-
void this.app.executeCommand(
429+
void this.app.commands.execute(
430430
"setContext",
431431
"codeQLVariantAnalysisRepositories.configError",
432432
false,
433433
);
434434
} else {
435435
this.config = undefined;
436-
void this.app.executeCommand(
436+
void this.app.commands.execute(
437437
"setContext",
438438
"codeQLVariantAnalysisRepositories.configError",
439439
true,

extensions/ql-vscode/test/__mocks__/appMock.ts

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function createMockApp({
1414
workspaceStoragePath = "/mock/workspace/storage/path",
1515
globalStoragePath = "/mock/global/storage/path",
1616
createEventEmitter = <T>() => new MockAppEventEmitter<T>(),
17-
executeCommand = jest.fn(() => Promise.resolve()),
1817
workspaceState = createMockMemento(),
1918
credentials = testCredentialsWithStub(),
2019
commands = createMockCommandManager(),
@@ -23,7 +22,6 @@ export function createMockApp({
2322
workspaceStoragePath?: string;
2423
globalStoragePath?: string;
2524
createEventEmitter?: <T>() => AppEventEmitter<T>;
26-
executeCommand?: () => Promise<void>;
2725
workspaceState?: Memento;
2826
credentials?: Credentials;
2927
commands?: AppCommandManager;
@@ -37,7 +35,6 @@ export function createMockApp({
3735
globalStoragePath,
3836
workspaceState,
3937
createEventEmitter,
40-
executeCommand,
4138
credentials,
4239
commands,
4340
};

extensions/ql-vscode/test/unit-tests/databases/config/db-config-store.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
createRemoteUserDefinedListDbItem,
2020
} from "../../../factories/db-item-factories";
2121
import { createMockApp } from "../../../__mocks__/appMock";
22+
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
2223

2324
describe("db config store", () => {
2425
const extensionPath = join(__dirname, "../../../..");
@@ -136,14 +137,16 @@ describe("db config store", () => {
136137
it("should set codeQLVariantAnalysisRepositories.configError to true when config has error", async () => {
137138
const testDataStoragePathInvalid = join(__dirname, "data", "invalid");
138139

140+
const executeCommand = jest.fn();
139141
const app = createMockApp({
140142
extensionPath,
141143
workspaceStoragePath: testDataStoragePathInvalid,
144+
commands: createMockCommandManager({ executeCommand }),
142145
});
143146
const configStore = new DbConfigStore(app, false);
144147
await configStore.initialize();
145148

146-
expect(app.executeCommand).toBeCalledWith(
149+
expect(executeCommand).toBeCalledWith(
147150
"setContext",
148151
"codeQLVariantAnalysisRepositories.configError",
149152
true,
@@ -152,14 +155,16 @@ describe("db config store", () => {
152155
});
153156

154157
it("should set codeQLVariantAnalysisRepositories.configError to false when config is valid", async () => {
158+
const executeCommand = jest.fn();
155159
const app = createMockApp({
156160
extensionPath,
157161
workspaceStoragePath: testDataStoragePath,
162+
commands: createMockCommandManager({ executeCommand }),
158163
});
159164
const configStore = new DbConfigStore(app, false);
160165
await configStore.initialize();
161166

162-
expect(app.executeCommand).toBeCalledWith(
167+
expect(executeCommand).toBeCalledWith(
163168
"setContext",
164169
"codeQLVariantAnalysisRepositories.configError",
165170
false,

0 commit comments

Comments
 (0)