Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(tests): update code action tests for the interactive apply path (#638)

arookieofcfa26ba842cf4
diff --git a/src/editor/refactor/refactorThis.test.ts b/src/editor/refactor/refactorThis.test.ts
index e3b624d19..f49a316f3 100644
--- a/src/editor/refactor/refactorThis.test.ts
+++ b/src/editor/refactor/refactorThis.test.ts
@@ -14,9 +14,11 @@ const lspCodeActionQuery = vi.fn(async (request: number, _doc: number, _range: u
);
const lspPrepareRename = vi.fn(async () => prepare);
let onApply: (() => void) | null = null;
-const lspApplyCodeAction = vi.fn(async () => {
+// applyCodeAction resolves the picked action, then executes it (interactive command support).
+const lspResolveCodeAction = vi.fn(async (_doc: number, action: CodeAction) => ok(action));
+const lspExecuteCodeAction = vi.fn(async () => {
onApply?.();
- return ok(null);
+ return ok([]);
});
const lspCodeActions = vi.fn(async () => ok([]));
const cancelRequest = vi.fn(async () => undefined);
@@ -31,7 +33,8 @@ vi.mock("@/platform/ipc", async (orig) => {
...actual.commands,
lspCodeActionQuery,
lspPrepareRename,
- lspApplyCodeAction,
+ lspResolveCodeAction,
+ lspExecuteCodeAction,
lspCodeActions,
cancelRequest,
languages,
@@ -185,7 +188,7 @@ describe("Refactor This", () => {
const items = (useLspPopup.getState().popup as { items: { label: string; run: () => void }[] }).items;
items.find((i) => i.label === "Inline…")!.run();
await new Promise((r) => setTimeout(r, 0));
- expect(lspApplyCodeAction).toHaveBeenCalledOnce();
+ expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
items.find((i) => i.label === "Rename…")!.run();
expect(rename).toHaveBeenCalledWith(v);
items.find((i) => i.label === "Safe Delete…")!.run();
@@ -240,7 +243,7 @@ describe("Refactor menu actions", () => {
it("apply the single matching action, or offer a choice", async () => {
query = answer([action("Move to a new file", "refactor.move.newFile")]);
await runRefactoring(editor(), "move");
- expect(lspApplyCodeAction).toHaveBeenCalledOnce();
+ expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
expect(lspCodeActionQuery.mock.calls[0]![3]).toEqual(["refactor.move"]);
closePopup();
diff --git a/src/editor/refactor/runKind.test.ts b/src/editor/refactor/runKind.test.ts
index ab1b993a8..cbeb77e69 100644
--- a/src/editor/refactor/runKind.test.ts
+++ b/src/editor/refactor/runKind.test.ts
@@ -5,11 +5,17 @@ import type { CodeAction } from "@/bindings";
let answer: () => unknown = () => ({ status: "ok", data: [] });
const lspCodeActions = vi.fn(async () => answer());
-const lspApplyCodeAction = vi.fn(async () => ({ status: "ok", data: null }));
+// applyCodeAction resolves the picked action, then executes it (interactive command support).
+const lspResolveCodeAction = vi.fn(async (_doc: number, action: CodeAction) => ({ status: "ok", data: action }));
+const lspExecuteCodeAction = vi.fn(async () => ({ status: "ok", data: [] }));
vi.mock("@/platform/ipc", async (orig) => {
const actual = await orig<typeof import("@/platform/ipc")>();
- return { ...actual, isTauri: () => true, commands: { ...actual.commands, lspCodeActions, lspApplyCodeAction } };
+ return {
+ ...actual,
+ isTauri: () => true,
+ commands: { ...actual.commands, lspCodeActions, lspResolveCodeAction, lspExecuteCodeAction },
+ };
});
const showHint = vi.fn();
vi.mock("@/editor/lsp/hint", () => ({ showHint }));
@@ -32,7 +38,8 @@ let view: EditorView | null = null;
afterEach(() => {
view?.destroy();
showHint.mockClear();
- lspApplyCodeAction.mockClear();
+ lspResolveCodeAction.mockClear();
+ lspExecuteCodeAction.mockClear();
});
function run(fallback: (reason: "notReady" | "error" | "empty") => Promise<boolean>) {
@@ -56,7 +63,7 @@ describe("runKindAction fallback", () => {
const fallback = vi.fn(async () => true);
await run(fallback);
expect(fallback).not.toHaveBeenCalled();
- expect(lspApplyCodeAction).toHaveBeenCalledOnce();
+ expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
});
it("falls back when the server is not ready or fails", async () => {