From 215023e85c20e159d78e9feda4adefd8faea9546 Mon Sep 17 00:00:00 2001 From: Muu Date: Tue, 17 Nov 2026 19:32:33 +0800 Subject: [PATCH] fix(plugins): wake problems-changed plugins on UI-side diagnostics (#3957) problems-changed was only forwarded for backend diagnostics events. Spelling and the other UI-side inspections publish through localDiagnostics, so a plugin drawing problems (Inspection Lens) kept showing a Typo after Add to Dictionary cleared it. Local diagnostic changes now post the same event. Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- .../plugins/__tests__/plugins.test.tsx | 35 +++++++++++++++++++ src/features/plugins/runtimeUi.tsx | 12 +++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/features/plugins/__tests__/plugins.test.tsx b/src/features/plugins/__tests__/plugins.test.tsx index ab9516699..7d99ef247 100644 --- a/src/features/plugins/__tests__/plugins.test.tsx +++ b/src/features/plugins/__tests__/plugins.test.tsx @@ -268,6 +268,41 @@ describe("plugin actions", () => { useProject.setState({ project: null }); } }); + + it("reports UI-side diagnostic changes (Typo saved to dictionary) to problems-changed plugins", async () => { + const posted: unknown[] = []; + setPluginsBackend({ + ...createMemoryPluginsBackend(), + eventKinds: async () => ["problems-changed"], + postEvents: async (events) => void posted.push(...events), + }); + const project = { root: "/p", trusted: true } as never; + act(() => useProject.setState({ project })); + const stop = startRuntimeUi(); + try { + await new Promise((r) => setTimeout(r, 20)); + // The file first has a Typo; saving the word to the dictionary re-checks + // it and clears the diagnostic through setFileDiagnostics -> + // publishLocalDiagnostics, not a backend `diagnostics` event. Plugins + // drawing problems must be woken by that clear too. + const { setFileDiagnostics } = await import("@/editor/lsp/diagnostics"); + const typo = { + range: { start: { line: 0, col: 0 }, end: { line: 0, col: 6 } }, + severity: "info" as const, + message: "Typo: In word 'mesage'", + source: "Spelling", + code: null, + }; + act(() => setFileDiagnostics("/p/a.txt", "spelling", [typo])); + await waitFor(() => expect(posted).toContainEqual({ kind: "problemsChanged" })); + posted.length = 0; + act(() => setFileDiagnostics("/p/a.txt", "spelling", [])); + await waitFor(() => expect(posted).toContainEqual({ kind: "problemsChanged" })); + } finally { + stop(); + act(() => useProject.setState({ project: null })); + } + }); }); describe("store", () => { diff --git a/src/features/plugins/runtimeUi.tsx b/src/features/plugins/runtimeUi.tsx index 6df03023f..f33af6c16 100644 --- a/src/features/plugins/runtimeUi.tsx +++ b/src/features/plugins/runtimeUi.tsx @@ -34,6 +34,7 @@ import { editorsFor, onEditorEvent } from "@/editor/api"; import { executeAction, executeActionOrThrow, getAction, onActionExecuted } from "@/platform/actions"; import { clearContext, setContext, type ContextValue } from "@/platform/context"; import { isTauri, onIdeEvent } from "@/platform/ipc"; +import { onLocalDiagnostics } from "@/platform/localDiagnostics"; import { isOpenable, openExternalUrl } from "@/platform/openUrl"; import { tx, VerbatimTextContext } from "@/platform/i18n"; import { useProject } from "@/platform/project"; @@ -364,16 +365,21 @@ function trackWorkbenchEvents(): () => void { if (wanted.has("vcs-changed")) post({ kind: "vcsChanged", value: e.root }); }); // Diagnostics arrive from language servers and builds without a file event; plugins - // that draw them (Inspection Lens) re-read the snapshot when this fires. - const offProblems = onIdeEvent("diagnostics", () => { + // that draw them (Inspection Lens) re-read the snapshot when this fires. Typo and + // other UI-side inspections publish through localDiagnostics instead, without an + // `IdeEvent::diagnostics`, so wire both sources to the same notification. + const problemsChanged = () => { if (wanted.has("problems-changed")) post({ kind: "problemsChanged" }); - }); + }; + const offProblems = onIdeEvent("diagnostics", problemsChanged); + const offLocalProblems = onLocalDiagnostics(problemsChanged); return () => { offEditor(); offActions(); offVcs(); offSettings(); offProblems(); + offLocalProblems(); if (postTimer) clearTimeout(postTimer); postTimer = null; queue = [];