mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(notifications): take down a failure balloon once a reload or server start succeeds (#4101)
A failed Maven/Gradle reload left its error balloon on screen after a later reload succeeded: syncTool notified on failure under build-sync-<tool> but never expired that key on success. A clean sync now expires it (the Notifications tool window keeps the entry). The same holds for the language-server prompts (not installed, JDK required, outdated build): a server turning ready expires them, for when the fix came from a settings page rather than the prompt's button. expireNotification leaves the state untouched when no balloon is shown. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
co-authored by
wildcatDownstairs
parent
4952a94064
commit
7a3f004235
@@ -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({
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -88,6 +88,8 @@ export function downloadJdkFor(args: DownloadJdkArgs): Promise<Sdk | null> {
|
||||
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<string>();
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string>();
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 }] : [])),
|
||||
}));
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user