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>
This commit is contained in:
Muu
2026-11-17 19:32:33 +08:00
committed by GitHub
co-authored by muutot
parent aab53f89b3
commit 215023e85c
2 changed files with 44 additions and 3 deletions
@@ -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", () => {
+9 -3
View File
@@ -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 = [];