Merge pull request #2212 from github/robertbrignull/app_executeCommand

Replace app.executeCommand with app.commands.execute
This commit is contained in:
Robert
2023-03-23 10:28:36 +00:00
committed by GitHub
6 changed files with 15 additions and 14 deletions

View File

@@ -7,7 +7,6 @@ import { AppCommandManager } from "./commands";
export interface App {
createEventEmitter<T>(): AppEventEmitter<T>;
executeCommand(command: string, ...args: any): Thenable<void>;
readonly mode: AppMode;
readonly logger: Logger;
readonly subscriptions: Disposable[];

View File

@@ -36,6 +36,10 @@ export type SingleSelectionCommandFunction<Item> = (
// See https://code.visualstudio.com/api/references/commands
export type BuiltInVsCodeCommands = {
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
setContext: (
key: `${"codeql" | "codeQL"}${string}`,
value: unknown,
) => Promise<void>;
"workbench.action.reloadWindow": () => Promise<void>;
};

View File

@@ -61,8 +61,4 @@ export class ExtensionApp implements App {
public createEventEmitter<T>(): AppEventEmitter<T> {
return new VSCodeAppEventEmitter<T>();
}
public executeCommand(command: string, ...args: any): Thenable<void> {
return vscode.commands.executeCommand(command, ...args);
}
}

View File

@@ -391,14 +391,14 @@ export class DbConfigStore extends DisposableObject {
if (this.configErrors.length === 0) {
this.config = newConfig;
await this.app.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
false,
);
} else {
this.config = undefined;
await this.app.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
true,
@@ -426,14 +426,14 @@ export class DbConfigStore extends DisposableObject {
if (this.configErrors.length === 0) {
this.config = newConfig;
void this.app.executeCommand(
void this.app.commands.execute(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
false,
);
} else {
this.config = undefined;
void this.app.executeCommand(
void this.app.commands.execute(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
true,

View File

@@ -14,7 +14,6 @@ export function createMockApp({
workspaceStoragePath = "/mock/workspace/storage/path",
globalStoragePath = "/mock/global/storage/path",
createEventEmitter = <T>() => new MockAppEventEmitter<T>(),
executeCommand = jest.fn(() => Promise.resolve()),
workspaceState = createMockMemento(),
credentials = testCredentialsWithStub(),
commands = createMockCommandManager(),
@@ -23,7 +22,6 @@ export function createMockApp({
workspaceStoragePath?: string;
globalStoragePath?: string;
createEventEmitter?: <T>() => AppEventEmitter<T>;
executeCommand?: () => Promise<void>;
workspaceState?: Memento;
credentials?: Credentials;
commands?: AppCommandManager;
@@ -37,7 +35,6 @@ export function createMockApp({
globalStoragePath,
workspaceState,
createEventEmitter,
executeCommand,
credentials,
commands,
};

View File

@@ -19,6 +19,7 @@ import {
createRemoteUserDefinedListDbItem,
} from "../../../factories/db-item-factories";
import { createMockApp } from "../../../__mocks__/appMock";
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
describe("db config store", () => {
const extensionPath = join(__dirname, "../../../..");
@@ -136,14 +137,16 @@ describe("db config store", () => {
it("should set codeQLVariantAnalysisRepositories.configError to true when config has error", async () => {
const testDataStoragePathInvalid = join(__dirname, "data", "invalid");
const executeCommand = jest.fn();
const app = createMockApp({
extensionPath,
workspaceStoragePath: testDataStoragePathInvalid,
commands: createMockCommandManager({ executeCommand }),
});
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(app.executeCommand).toBeCalledWith(
expect(executeCommand).toBeCalledWith(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
true,
@@ -152,14 +155,16 @@ describe("db config store", () => {
});
it("should set codeQLVariantAnalysisRepositories.configError to false when config is valid", async () => {
const executeCommand = jest.fn();
const app = createMockApp({
extensionPath,
workspaceStoragePath: testDataStoragePath,
commands: createMockCommandManager({ executeCommand }),
});
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(app.executeCommand).toBeCalledWith(
expect(executeCommand).toBeCalledWith(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
false,