Convert extensions/ql-vscode/src/helpers.ts to call typed commands
This commit is contained in:
@@ -42,6 +42,7 @@ export type BuiltInVsCodeCommands = {
|
||||
value: unknown,
|
||||
) => Promise<void>;
|
||||
"workbench.action.reloadWindow": () => Promise<void>;
|
||||
"vscode.openFolder": (uri: Uri) => Promise<void>;
|
||||
};
|
||||
|
||||
// Commands that are available before the extension is fully activated.
|
||||
|
||||
@@ -573,7 +573,7 @@ async function installOrUpdateThenTryActivate(
|
||||
await installOrUpdateDistribution(ctx, app, distributionManager, config);
|
||||
|
||||
try {
|
||||
await prepareCodeTour();
|
||||
await prepareCodeTour(app.commands);
|
||||
} catch (e: unknown) {
|
||||
void extLogger.log(
|
||||
`Could not open tutorial workspace automatically: ${getErrorMessage(e)}`,
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
window as Window,
|
||||
workspace,
|
||||
env,
|
||||
commands,
|
||||
} from "vscode";
|
||||
import { CodeQLCliServer, QlpacksInfo } from "./cli";
|
||||
import { UserCancellationException } from "./progress";
|
||||
@@ -27,6 +26,7 @@ import { RedactableError } from "./pure/errors";
|
||||
import { getQlPackPath } from "./pure/ql";
|
||||
import { dbSchemeToLanguage } from "./common/query-language";
|
||||
import { isCodespacesTemplate } from "./config";
|
||||
import { AppCommandManager } from "./common/commands";
|
||||
|
||||
// Shared temporary folder for the extension.
|
||||
export const tmpDir = dirSync({
|
||||
@@ -271,7 +271,9 @@ export function isFolderAlreadyInWorkspace(folderName: string) {
|
||||
/** Check if the current workspace is the CodeTour and open the workspace folder.
|
||||
* Without this, we can't run the code tour correctly.
|
||||
**/
|
||||
export async function prepareCodeTour(): Promise<void> {
|
||||
export async function prepareCodeTour(
|
||||
commandManager: AppCommandManager,
|
||||
): Promise<void> {
|
||||
if (workspace.workspaceFolders?.length) {
|
||||
const currentFolder = workspace.workspaceFolders[0].uri.fsPath;
|
||||
|
||||
@@ -308,7 +310,7 @@ export async function prepareCodeTour(): Promise<void> {
|
||||
`In prepareCodeTour() method, going to open the tutorial workspace file: ${tutorialWorkspacePath}`,
|
||||
);
|
||||
|
||||
await commands.executeCommand("vscode.openFolder", tutorialWorkspaceUri);
|
||||
await commandManager.execute("vscode.openFolder", tutorialWorkspaceUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
commands,
|
||||
EnvironmentVariableCollection,
|
||||
EnvironmentVariableMutator,
|
||||
Event,
|
||||
@@ -41,6 +40,7 @@ import {
|
||||
import { reportStreamProgress } from "../../../src/progress";
|
||||
import { QueryLanguage } from "../../../src/common/query-language";
|
||||
import { Setting } from "../../../src/config";
|
||||
import { createMockCommandManager } from "../../__mocks__/commandsMock";
|
||||
|
||||
describe("helpers", () => {
|
||||
describe("Invocation rate limiter", () => {
|
||||
@@ -612,13 +612,11 @@ describe("prepareCodeTour", () => {
|
||||
await mkdir(tourDirPath);
|
||||
|
||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
||||
commandSpy.mockImplementation(() => Promise.resolve());
|
||||
|
||||
await prepareCodeTour();
|
||||
const executeCommand = jest.fn();
|
||||
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||
|
||||
expect(showInformationMessageSpy).toHaveBeenCalled();
|
||||
expect(commandSpy).toHaveBeenCalledWith(
|
||||
expect(executeCommand).toHaveBeenCalledWith(
|
||||
"vscode.openFolder",
|
||||
expect.objectContaining({
|
||||
path: Uri.parse(tutorialWorkspacePath).fsPath,
|
||||
@@ -641,12 +639,10 @@ describe("prepareCodeTour", () => {
|
||||
await mkdir(tourDirPath);
|
||||
|
||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
||||
commandSpy.mockImplementation(() => Promise.resolve());
|
||||
const executeCommand = jest.fn();
|
||||
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||
|
||||
await prepareCodeTour();
|
||||
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
expect(executeCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -658,24 +654,20 @@ describe("prepareCodeTour", () => {
|
||||
await mkdir(tourDirPath);
|
||||
|
||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
||||
commandSpy.mockImplementation(() => Promise.resolve());
|
||||
const executeCommand = jest.fn();
|
||||
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||
|
||||
await prepareCodeTour();
|
||||
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
expect(executeCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("if we're in a different repo with no tour", () => {
|
||||
it("should not open the tutorial workspace", async () => {
|
||||
// spy that we open the workspace file by calling the 'vscode.openFolder' command
|
||||
const commandSpy = jest.spyOn(commands, "executeCommand");
|
||||
commandSpy.mockImplementation(() => Promise.resolve());
|
||||
const executeCommand = jest.fn();
|
||||
await prepareCodeTour(createMockCommandManager({ executeCommand }));
|
||||
|
||||
await prepareCodeTour();
|
||||
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
expect(executeCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user