From 8be62cb8954af7b6869650a119a8d60f178ca1d2 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 6 Dec 2026 08:08:09 +0800 Subject: [PATCH] fix(lsp): drop parameter info on its way when Escape comes before it shows (#8313) The parameter info requested after accepting a call completion with unknown arguments still appeared when Escape was pressed or the editor left before the server answered, and Escape before an auto-popup showed didn't cancel it. That request now counts as automatic, and Escape cancels pending automatic requests even with no popup shown, without consuming the key. --- src/editor/lsp/signature.test.ts | 12 ++++++++++++ src/editor/lsp/signature.ts | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/editor/lsp/signature.test.ts b/src/editor/lsp/signature.test.ts index 0b78a9ea34..18a7c25e3d 100644 --- a/src/editor/lsp/signature.test.ts +++ b/src/editor/lsp/signature.test.ts @@ -265,6 +265,18 @@ describe("parameter info replies", () => { expect(shown(view)).toBeNull(); }); + it("doesn't open parameter info after a completed call once Escape was pressed before the reply", async () => { + const inside = pending(); + lspSignatureHelp.mockReturnValueOnce(inside.promise as never); + const view = editor(); + const left = parameterInfoOrLeave(view, 2); + escape(view); + inside.resolve(named("f")); + await left; + expect(shown(view)).toBeNull(); + expect(view.state.selection.main.head).toBe(2); + }); + it("stays closed after Escape when an automatic reply was already on its way", async () => { const late = pending(); lspSignatureHelp.mockResolvedValueOnce(named("f") as never).mockReturnValueOnce(late.promise as never); diff --git a/src/editor/lsp/signature.ts b/src/editor/lsp/signature.ts index 2357668e46..006f81a57c 100644 --- a/src/editor/lsp/signature.ts +++ b/src/editor/lsp/signature.ts @@ -249,12 +249,17 @@ async function fetchSignature(view: EditorView, explicit: boolean) { export async function parameterInfoOrLeave(view: EditorView, inside: number) { const doc = docOf(view); const state = view.state; + // An automatic request: Escape or leaving the editor before the reply drops it. + let order = requests.get(view); + if (!order) requests.set(view, (order = { sent: 0 })); + const id = ++order.sent; let help: SignatureHelp | null = null; try { if (doc) help = await lspRequest(() => commands.lspSignatureHelp(doc.doc, offsetToPos(state.doc, inside))); } catch { // No signature help: treated as nothing to fill in. } + if (id <= (order.dismissed ?? 0)) return; if (view.state.doc !== state.doc || view.state.selection.main.head !== inside) return; if (help?.signatures.some((sig) => sig.parameters.length)) view.dispatch({ effects: setSignature.of({ pos: inside, help }) }); @@ -423,8 +428,9 @@ export function signatureExtension(): Extension { { key: "Escape", run: (view) => { - if (!view.state.field(signatureField, false)) return false; + // Also before the popup shows: an automatic one on its way stays away, and Escape goes on. view.plugin(signaturePlugin)?.dismiss(); + if (!view.state.field(signatureField, false)) return false; view.dispatch({ effects: setSignature.of(null) }); return true; },