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.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 08:08:09 +08:00
1 джерело 9faaae33ae
коміт 8be62cb895
2 files changed
+19 -1

No files matched your search

+12
Переглянути файл
@@ -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);
+7 -1
Переглянути файл
@@ -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;
},