дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-18 07:35:39 +02:00
Порівняти коміти
1
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
6ed12adb6d |
No files matched your search
@@ -7,6 +7,7 @@ vi.mock("@/platform/ipc", async (original) => {
|
||||
});
|
||||
|
||||
const { cancellable } = await import("./signature");
|
||||
const { isCancelled } = await import("@/platform/ipc");
|
||||
|
||||
describe("cancellable refactoring requests", () => {
|
||||
it("cancels the request in flight when the dialog closes", async () => {
|
||||
@@ -30,4 +31,13 @@ describe("cancellable refactoring requests", () => {
|
||||
run.abort();
|
||||
expect(cancelRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("never sends a request the dialog closed before", async () => {
|
||||
const run = new AbortController();
|
||||
run.abort();
|
||||
const send = vi.fn(async () => "sent");
|
||||
const err = await cancellable(run.signal, send).catch((e: unknown) => e);
|
||||
expect(isCancelled(err)).toBe(true);
|
||||
expect(send).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -158,9 +158,9 @@ export async function extractInterface(
|
||||
const summary = summarizeWorkspaceEdit(edit);
|
||||
if (!summary.files) return { status: "stay", error: "Nothing to change" };
|
||||
const created = edit.files.find((f) => f.kind === "create")?.path;
|
||||
const apply = async () => {
|
||||
await applyEdit(view, edit);
|
||||
if (created) await editorService().openFile(created, { focus: true });
|
||||
const apply = async (cancel?: AbortSignal) => {
|
||||
await applyEdit(view, edit, cancel);
|
||||
if (created && !cancel?.aborted) await editorService().openFile(created, { focus: true });
|
||||
};
|
||||
if (preview) {
|
||||
openPopup({
|
||||
@@ -171,7 +171,7 @@ export async function extractInterface(
|
||||
onConfirm: () => void apply(),
|
||||
});
|
||||
} else {
|
||||
await apply();
|
||||
await apply(signal);
|
||||
}
|
||||
return { status: "done" };
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import { showHint } from "@/editor/lsp/hint";
|
||||
import { openPopup } from "@/editor/lsp/popupStore";
|
||||
import { summarizeWorkspaceEdit } from "@/editor/lsp/workspaceEdit";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { commands, isCancelled, nextRequestId, unavailableText } from "@/platform/ipc";
|
||||
import { IpcError, commands, isCancelled, nextRequestId, unavailableText } from "@/platform/ipc";
|
||||
import { ask } from "@/workbench/messages";
|
||||
import { cannotPerform } from "./catalog";
|
||||
|
||||
@@ -129,9 +129,11 @@ export async function startChangeSignature(view: EditorView): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function applyEdit(view: EditorView, edit: WorkspaceEdit) {
|
||||
export async function applyEdit(view: EditorView, edit: WorkspaceEdit, signal?: AbortSignal) {
|
||||
try {
|
||||
await whenAllSynced();
|
||||
// The dialog closed while the editors were syncing: nothing is applied.
|
||||
if (signal?.aborted) return;
|
||||
await lspRequest(() => commands.applyWorkspaceEdit(edit));
|
||||
} catch (e) {
|
||||
reportLspError(view, e, true);
|
||||
@@ -140,6 +142,8 @@ export async function applyEdit(view: EditorView, edit: WorkspaceEdit) {
|
||||
|
||||
/** Sends `send(id)` with a fresh request id that `signal` cancels. */
|
||||
export async function cancellable<T>(signal: AbortSignal | undefined, send: (id: number) => Promise<T>): Promise<T> {
|
||||
// Closed before the request went out: it never does (a cancel can't reach an unsent request).
|
||||
if (signal?.aborted) throw new IpcError({ kind: "cancelled", message: "Cancelled" });
|
||||
const id = nextRequestId();
|
||||
const abort = () => void commands.cancelRequest(id);
|
||||
signal?.addEventListener("abort", abort);
|
||||
@@ -210,7 +214,7 @@ export async function changeSignature(
|
||||
onConfirm: () => void applyEdit(view, edit),
|
||||
});
|
||||
} else {
|
||||
await applyEdit(view, edit);
|
||||
await applyEdit(view, edit, signal);
|
||||
}
|
||||
return { status: "done" };
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача