fix(lsp): keep Parameter Info closed after Escape or leaving the editor (#8305)

Escape on Parameter Info right after typing an argument closed the popup and the debounced refresh of the last keystroke brought it back about 120 ms later; leaving the editor did the same, and the auto-popup still opened on an editor already left. Escape and blur now cancel the pending refresh and auto-popup timer and drop replies to automatic requests sent before that; explicit Parameter Info and typing ( or , again still open it.

Co-authored-by: audichuang <[email protected]>
Цей коміт міститься в:
audichuang authored and GitHub committed 2026-12-06 08:05:23 +08:00
1 джерело 487ad35181
коміт 9faaae33ae
3 files changed
+73 -2

No files matched your search

+3
Переглянути файл
@@ -151,6 +151,9 @@ test("C# parameter info bolds the argument being typed, `params` included", asyn
// The third argument: past the last parameter. Reopened, so the old popup can't answer for it.
await page.keyboard.press("Escape");
await expect(popup).toBeHidden();
// Past the refresh the typing scheduled: it must not bring the closed popup back.
await page.waitForTimeout(500);
await expect(popup).toBeHidden({ timeout: 10 });
await page.keyboard.press("Meta+p");
await expect(popup.locator("b")).toHaveText("args");
if (SHOTS) await page.screenshot({ path: `${SHOTS}/csharp-parameter-info.png` });
+53
Переглянути файл
@@ -224,6 +224,59 @@ describe("parameter info replies", () => {
await vi.waitFor(() => expect(shown(a)).toBe("f"));
expect(shown(b)).toBe("g");
});
const escape = (view: EditorView) =>
view.contentDOM.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
it("stays closed after Escape while the refresh for the last keystroke is pending", async () => {
lspSignatureHelp.mockResolvedValueOnce(named("f") as never);
const view = editor();
triggerSignatureHelp(view, true);
await vi.waitFor(() => expect(shown(view)).toBe("f"));
typeChar(view, ",");
escape(view);
expect(shown(view)).toBeNull();
await new Promise((r) => setTimeout(r, 300));
expect(shown(view)).toBeNull();
triggerSignatureHelp(view, true);
await vi.waitFor(() => expect(shown(view)).not.toBeNull());
});
it("stays closed after the editor loses focus while a refresh is pending", async () => {
lspSignatureHelp.mockResolvedValueOnce(named("f") as never);
const view = editor();
view.focus();
triggerSignatureHelp(view, true);
await vi.waitFor(() => expect(shown(view)).toBe("f"));
typeChar(view, ",");
view.contentDOM.blur();
await vi.waitFor(() => expect(shown(view)).toBeNull());
await new Promise((r) => setTimeout(r, 300));
expect(shown(view)).toBeNull();
});
it("doesn't open the auto-popup once the editor lost focus before it showed", async () => {
const view = editor("f", 1);
view.focus();
typeChar(view, "(");
view.contentDOM.blur();
await new Promise((r) => setTimeout(r, 1200));
expect(lspSignatureHelp).not.toHaveBeenCalled();
expect(shown(view)).toBeNull();
});
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);
const view = editor();
triggerSignatureHelp(view, true);
await vi.waitFor(() => expect(shown(view)).toBe("f"));
triggerSignatureHelp(view, false);
escape(view);
late.resolve(named("f2"));
await settle();
expect(shown(view)).toBeNull();
});
});
describe("C# parameter info", () => {
+17 -2
Переглянути файл
@@ -188,10 +188,13 @@ function signatureTooltip(s: SigState): Tooltip {
};
}
/** Per view: requests sent, and the tooltip value the newest shown reply set, with the document and caret it was asked at. */
/**
* Per view: requests sent, the newest request sent before the user closed the tooltip,
* and the tooltip value the newest shown reply set, with the document and caret it was asked at.
*/
const requests = new WeakMap<
EditorView,
{ sent: number; shown?: { id: number; value: SigState; doc: Text; head: number } }
{ sent: number; dismissed?: number; shown?: { id: number; value: SigState; doc: Text; head: number } }
>();
async function fetchSignature(view: EditorView, explicit: boolean) {
@@ -204,6 +207,8 @@ async function fetchSignature(view: EditorView, explicit: boolean) {
const head = state.selection.main.head;
// A late reply asked at another caret never overrides what a newer request still shows for this one.
const superseded = () => {
// The user closed the tooltip after this automatic request was sent: its reply must not reopen it.
if (!explicit && id <= (order.dismissed ?? 0)) return true;
const shown = order.shown;
return (
!!shown &&
@@ -273,7 +278,16 @@ const signaturePlugin = ViewPlugin.fromClass(
clearTimeout(this.popupTimer);
this.popupTimer = setTimeout(() => void fetchSignature(this.view, false), Math.max(0, p.parameterInfoDelay));
}
/** The user closed the tooltip: automatic requests already scheduled or sent don't reopen it. */
dismiss() {
clearTimeout(this.popupTimer);
this.refresh.cancel();
const order = requests.get(this.view);
if (order) order.dismissed = order.sent;
}
update(u: ViewUpdate) {
// Leaving the editor closes the tooltip like Escape does (`focusChangeEffect` below), and nothing pending opens it.
if (u.focusChanged && !u.view.hasFocus) this.dismiss();
const active = u.state.field(signatureField, false);
let typedTrigger = false;
if (
@@ -410,6 +424,7 @@ export function signatureExtension(): Extension {
key: "Escape",
run: (view) => {
if (!view.state.field(signatureField, false)) return false;
view.plugin(signaturePlugin)?.dismiss();
view.dispatch({ effects: setSignature.of(null) });
return true;
},