Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai a3708fa7bc fix(refactor): a dialog closed while editors sync never sends its request 2026-11-16 19:25:30 +08:00
3 змінених файлів з 32 додано та 9 видалено

No files matched your search

+13
Переглянути файл
@@ -40,4 +40,17 @@ describe("cancellable refactoring requests", () => {
expect(isCancelled(err)).toBe(true);
expect(send).not.toHaveBeenCalled();
});
it("tells the sender once the dialog closed after the request was handed over", async () => {
const run = new AbortController();
let wanted!: () => boolean;
const reply = cancellable(run.signal, async (_id, w) => {
wanted = w;
return "sent";
});
expect(wanted()).toBe(true);
run.abort();
expect(wanted()).toBe(false);
await reply;
});
});
+4 -3
Переглянути файл
@@ -136,9 +136,10 @@ export async function extractInterface(
for (;;) {
await whenSynced(view);
const token: string | null = confirmation;
extracted = await cancellable(signal, (id) =>
lspRequest(() =>
commands.lspExtractInterface(id, request.doc, request.pos, [...members], name, pkg.json, token),
extracted = await cancellable(signal, (id, wanted) =>
lspRequest(
() => commands.lspExtractInterface(id, request.doc, request.pos, [...members], name, pkg.json, token),
wanted,
),
);
if (signal?.aborted) return { status: "stay" };
+15 -6
Переглянути файл
@@ -134,21 +134,30 @@ export async function applyEdit(view: EditorView, edit: WorkspaceEdit, signal?:
await whenAllSynced();
// The dialog closed while the editors were syncing: nothing is applied.
if (signal?.aborted) return;
await lspRequest(() => commands.applyWorkspaceEdit(edit));
await lspRequest(
() => commands.applyWorkspaceEdit(edit),
() => !signal?.aborted,
);
} catch (e) {
reportLspError(view, e, true);
}
}
/** 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> {
/**
* Sends `send(id, wanted)` with a fresh request id that `signal` cancels. `wanted` goes to
* `lspRequest`, which syncs editors first: a dialog closed meanwhile never sends the request.
*/
export async function cancellable<T>(
signal: AbortSignal | undefined,
send: (id: number, wanted: () => boolean) => 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);
try {
return await send(id);
return await send(id, () => !signal?.aborted);
} finally {
signal?.removeEventListener("abort", abort);
}
@@ -186,8 +195,8 @@ export async function changeSignature(
for (;;) {
await whenSynced(view);
const token: string | null = confirmation;
changed = await cancellable(signal, (id) =>
lspRequest(() => commands.lspChangeSignature(id, request.doc, request.pos, signature, delegate, token)),
changed = await cancellable(signal, (id, wanted) =>
lspRequest(() => commands.lspChangeSignature(id, request.doc, request.pos, signature, delegate, token), wanted),
);
if (signal?.aborted) return { status: "stay" };
const fatal = changed.problems.find((p) => p.severity === "fatal");