diff --git a/src/features/build-tools/store.ts b/src/features/build-tools/store.ts index ca5eccce5..a0b947709 100644 --- a/src/features/build-tools/store.ts +++ b/src/features/build-tools/store.ts @@ -657,6 +657,8 @@ export async function syncTool(tool: BuildTool, buildDir: string | null = null): ...buildToolRecovery(error), key: `build-sync-${tool}`, }); + // A clean reload takes down the previous failure's balloon; the log keeps it. + else notifications().expire?.(`build-sync-${tool}`); } catch (e) { if (!isCancelled(e)) notifications().notify({ diff --git a/src/features/tools/__tests__/readyExpiry.test.ts b/src/features/tools/__tests__/readyExpiry.test.ts new file mode 100644 index 000000000..68d7fdcc3 --- /dev/null +++ b/src/features/tools/__tests__/readyExpiry.test.ts @@ -0,0 +1,38 @@ +/** A server that starts after all takes down the balloons that said it could not. */ +import { afterEach, expect, it, vi } from "vitest"; +import type { IdeEvent } from "@/bindings"; +import { emitLocalIdeEvent } from "@/platform/ipc"; +import { provideNotificationService } from "@/workbench/contributions"; +import { installServerReadyExpiry } from "../missing"; + +const expire = vi.fn(); +provideNotificationService({ notify: () => {}, expire }); +const dispose = installServerReadyExpiry(); +afterEach(() => expire.mockClear()); + +const status = (s: string) => + emitLocalIdeEvent({ + type: "languageServer", + server: 1, + name: "jdtls", + status: s, + message: null, + } as unknown as IdeEvent); + +it.each(["starting", "busy", "missing", "misconfigured", "crashed"])( + "keeps the prompts while the server is %s", + (s) => { + status(s); + expect(expire).not.toHaveBeenCalled(); + }, +); + +it("expires the missing, JDK and expired-build prompts once the server is ready", () => { + status("ready"); + expect(expire.mock.calls.map(([key]) => key)).toEqual([ + "lsp-missing-jdtls", + "jdk-required-jdtls", + "lsp-expired-jdtls", + ]); + dispose(); +}); diff --git a/src/features/tools/expired.ts b/src/features/tools/expired.ts index dedf7762d..a8b0a6482 100644 --- a/src/features/tools/expired.ts +++ b/src/features/tools/expired.ts @@ -11,11 +11,13 @@ import { installTool, refreshTools, SETTINGS_PAGE_ID, toolByName } from "./store export const isExpiredBuild = (message: string | null) => !!message && /This build of .+ has expired/.test(message); +export const expiredKey = (name: string) => `lsp-expired-${name}`; + export async function promptUpdateExpired(name: string) { await refreshTools(); const tool = toolByName(name); const display = tool?.displayName ?? name; - const key = `lsp-expired-${name}`; + const key = expiredKey(name); const installable = tool?.canInstall && (tool.status === "installed" || tool.status === "onPath"); notifications().notify({ group: "lsp", diff --git a/src/features/tools/index.ts b/src/features/tools/index.ts index db5025faa..aafcb909f 100644 --- a/src/features/tools/index.ts +++ b/src/features/tools/index.ts @@ -10,7 +10,12 @@ import { executeAction, registerActions } from "@/platform/actions"; import { registerSettingsPage } from "@/workbench/contributions"; import { installExpiredServerPrompts } from "./expired"; import { installJdkPrompts, registerJdkActions } from "./jdk"; -import { installMissingServerPrompts, installServerWarningPrompts, promptInstall } from "./missing"; +import { + installMissingServerPrompts, + installServerReadyExpiry, + installServerWarningPrompts, + promptInstall, +} from "./missing"; import { installTool, refreshTools, SETTINGS_PAGE_ID, toolByName, useTools } from "./store"; /** The Language Servers page (also used by the Settings window). */ @@ -85,6 +90,7 @@ export function activate(): () => void { }, ]), installMissingServerPrompts(), + installServerReadyExpiry(), installServerWarningPrompts(), installExpiredServerPrompts(), registerJdkActions(), diff --git a/src/features/tools/jdk.ts b/src/features/tools/jdk.ts index f3b66b85a..7a68f11bd 100644 --- a/src/features/tools/jdk.ts +++ b/src/features/tools/jdk.ts @@ -88,6 +88,8 @@ export function downloadJdkFor(args: DownloadJdkArgs): Promise { return p; } +export const jdkRequiredKey = (name: string) => `jdk-required-${name}`; + /** A language server that can't start without a newer JDK (jdtls): say so once, with the one-click download. */ export function installJdkPrompts(): () => void { const prompted = new Set(); @@ -99,7 +101,7 @@ export function installJdkPrompts(): () => void { notifications().notify({ group: "lsp", level: "warning", - key: `jdk-required-${e.name}`, + key: jdkRequiredKey(e.name), sticky: true, title: `${e.name} needs JDK ${need.version} to run`, body: e.message ?? undefined, diff --git a/src/features/tools/missing.ts b/src/features/tools/missing.ts index ded4e1793..b923a08d7 100644 --- a/src/features/tools/missing.ts +++ b/src/features/tools/missing.ts @@ -7,6 +7,8 @@ import { executeAction } from "@/platform/actions"; import { onIdeEvent } from "@/platform/ipc"; import { notifications } from "@/workbench/contributions"; +import { expiredKey } from "./expired"; +import { jdkRequiredKey } from "./jdk"; import { installTool, refreshTools, SETTINGS_PAGE_ID, toolByName, useTools } from "./store"; import { tx } from "@/platform/i18n"; @@ -77,6 +79,17 @@ export function installMissingServerPrompts(): () => void { }); } +/** + * A server that starts after all (installed from the Language Servers page, given a JDK, + * updated) takes down the balloons that said it could not. + */ +export function installServerReadyExpiry(): () => void { + return onIdeEvent("languageServer", (e) => { + if (e.status !== "ready") return; + for (const key of [missingKey(e.name), jdkRequiredKey(e.name), expiredKey(e.name)]) notifications().expire?.(key); + }); +} + /** A system server that lacks a capability can be replaced by the managed tool. */ export function installServerWarningPrompts(): () => void { const prompted = new Set(); diff --git a/src/workbench/buildToolRecovery.test.ts b/src/workbench/buildToolRecovery.test.ts index 3e43d9628..12a4f335c 100644 --- a/src/workbench/buildToolRecovery.test.ts +++ b/src/workbench/buildToolRecovery.test.ts @@ -12,6 +12,7 @@ vi.mock("@/platform/ipc", async (original) => { buildSync: mocks.sync, runStart: mocks.start, runConfigs: async () => ({ status: "ok", data: [] }), + showSystemNotification: async () => ({ status: "ok", data: null }), }, }; }); @@ -24,6 +25,7 @@ vi.mock("@tauri-apps/api/core", async (original) => ({ import { useProject } from "@/platform/project"; import { provideNotificationService } from "@/workbench/contributions"; +import { notificationServiceImpl, useNotifications } from "@/workbench/notificationStore"; import { resetBuild, syncTool, useBuild } from "../features/build-tools/store"; import { resetRuns, startRun } from "../features/run/store"; @@ -36,6 +38,7 @@ beforeEach(() => { afterEach(() => { resetBuild(); resetRuns(); + useNotifications.setState({ items: [] }); }); it.each(["maven", "gradle"] as const)("offers settings for %s sync failures, returned or thrown", async (tool) => { @@ -61,6 +64,29 @@ it.each(["maven", "gradle"] as const)("offers settings for %s sync failures, ret ); }); +// #4092: the failure balloon outlived the reload that fixed it. +it.each(["maven", "gradle"] as const)("a clean %s reload takes down the failure balloon", async (tool) => { + provideNotificationService(notificationServiceImpl); + const name = tool === "maven" ? "Maven" : "Gradle"; + const shown = () => + useNotifications + .getState() + .items.filter((n) => n.balloon) + .map((n) => n.title); + mocks.sync.mockRejectedValueOnce(new Error("cannot start mvn.cmd: program not found")); + await syncTool(tool); + expect(shown()).toEqual([`Cannot reload ${name} projects`]); + + const clean = (tool === "maven" + ? { maven: { syncError: null }, gradle: [] } + : { maven: null, gradle: [{ syncError: null }] }) as unknown as BuildModel; + mocks.sync.mockResolvedValueOnce({ status: "ok", data: clean }); + await syncTool(tool); + expect(shown()).toEqual([]); + // Still in the Notifications tool window. + expect(useNotifications.getState().items.map((n) => n.title)).toEqual([`Cannot reload ${name} projects`]); +}); + it.each(["maven", "gradle"] as const)("offers settings when a %s run cannot start", async (kind) => { const command = kind === "maven" ? "mvn" : "gradle"; const config: RunConfig = { diff --git a/src/workbench/notificationStore.ts b/src/workbench/notificationStore.ts index 4b47e682e..9748a6535 100644 --- a/src/workbench/notificationStore.ts +++ b/src/workbench/notificationStore.ts @@ -177,6 +177,8 @@ export function dismissBalloon(id: number) { /** Hides the balloon for `key`: the condition it reported no longer holds. */ export function expireNotification(key: string) { + // Called on every success (a server turning ready): nothing shown, no new state. + if (!useNotifications.getState().items.some((x) => x.key === key && x.balloon)) return; useNotifications.setState((s) => ({ items: s.items.flatMap((x) => (x.key !== key || !x.balloon ? [x] : x.logged ? [{ ...x, balloon: false }] : [])), })); diff --git a/src/workbench/projectNotifications.test.ts b/src/workbench/projectNotifications.test.ts index 9294cab58..4f0fadb08 100644 --- a/src/workbench/projectNotifications.test.ts +++ b/src/workbench/projectNotifications.test.ts @@ -1,7 +1,7 @@ import { afterEach, describe, expect, it } from "vitest"; import { useProject } from "@/platform/project"; import { activateWorkbench } from "./activate"; -import { notify, useNotifications } from "./notificationStore"; +import { expireNotification, notify, useNotifications } from "./notificationStore"; afterEach(() => { useNotifications.setState({ items: [] }); @@ -24,3 +24,16 @@ describe("notifications across project changes", () => { } }); }); + +describe("expiring a notification", () => { + it("hides its balloon, keeps it in the log, and leaves the state alone when nothing is shown", () => { + notify({ level: "error", title: "Cannot reload Maven projects", key: "build-sync-maven" }); + expireNotification("build-sync-maven"); + const [item] = useNotifications.getState().items; + expect(item).toMatchObject({ title: "Cannot reload Maven projects", balloon: false }); + const before = useNotifications.getState(); + expireNotification("build-sync-maven"); + expireNotification("unknown"); + expect(useNotifications.getState()).toBe(before); + }); +});