feat(tools): show language server updates in the status bar

The Language Servers status bar widget marks that an installed server has a
newer version, and its row in the popup gets an Update button. Updates are
looked up a minute after startup, at most once a day; the result is shared
by the windows and drops what was installed.
Цей коміт міститься в:
l0ng-ai committed 2026-12-02 17:32:49 +08:00
1 джерело 74f61a3540
коміт a4866b0323
8 files changed
+188 -7

No files matched your search

+6
Переглянути файл
@@ -83,3 +83,9 @@
-webkit-user-select: text;
user-select: text;
}
/* Some server has a newer version (Update in its row). */
.updateBadge {
margin-left: 4px;
color: var(--accent);
}
+28 -1
Переглянути файл
@@ -3,6 +3,7 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { registerAction } from "@/platform/actions";
import { ServerStatus } from "./ServerStatus";
import { useServers, type ServerEntry } from "./servers";
import { useToolUpdates } from "@/workbench/contributions";
const ISSUE_49 =
"jdtls needs JDK 25 or newer to run (found JDK 8, 17, 21). Download JDK 25, or pick an installed one in Settings › Languages & Frameworks › Java › Language Server › JDK (it restarts automatically); the project can still target an older Java version.";
@@ -10,9 +11,35 @@ const ISSUE_49 =
const server = (status: ServerEntry["status"], message: string | null): ServerEntry =>
({ id: 1, name: "jdtls", status, message, languages: ["Java"], root: null }) as unknown as ServerEntry;
afterEach(() => useServers.setState({ servers: new Map() }));
afterEach(() => {
useServers.setState({ servers: new Map() });
useToolUpdates.setState({ latest: {} });
});
describe("Language server status popup", () => {
it("marks a server with a newer version and updates it from its row (#7365)", () => {
const install = vi.fn();
const off = registerAction({ id: "tools.install", title: "Install", run: ({ arg }) => install(arg) });
useServers.setState({ servers: new Map([[1 as never, server("ready", null)]]) });
useToolUpdates.setState({ latest: { jdtls: "1.64.0" } });
render(<ServerStatus />);
expect(screen.getByLabelText("Language server updates are available")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: /Language servers/ }));
fireEvent.click(screen.getByRole("button", { name: "Update jdtls" }));
expect(install).toHaveBeenCalledWith("jdtls");
off();
});
it("shows no update mark without one", () => {
const off = registerAction({ id: "tools.install", title: "Install", run: () => {} });
useServers.setState({ servers: new Map([[1 as never, server("ready", null)]]) });
render(<ServerStatus />);
expect(screen.queryByLabelText("Language server updates are available")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: /Language servers/ }));
expect(screen.queryByRole("button", { name: "Update jdtls" })).toBeNull();
off();
});
it("offers Download JDK N when jdtls can't start for want of a JDK", () => {
const run = vi.fn();
const off = registerAction({ id: "java.downloadJdk", title: "Download JDK…", run: ({ arg }) => run(arg) });
+27 -1
Переглянути файл
@@ -2,7 +2,7 @@
import { useMemo, useRef, useState } from "react";
import clsx from "clsx";
import { getAction, executeAction } from "@/platform/actions";
import { BarButton, Button, IconButton, Popup, T } from "@/ui";
import { BarButton, Button, Icon, IconButton, Popup, T } from "@/ui";
import { downloadJdkActions } from "@/platform/jdk";
import { relativePath, useProject } from "@/platform/project";
import {
@@ -17,6 +17,7 @@ import {
} from "./servers";
import styles from "./ServerStatus.module.css";
import { tx } from "@/platform/i18n";
import { useToolUpdates } from "@/workbench/contributions";
export function ServerStatus() {
const map = useServers((s) => s.servers);
@@ -28,6 +29,9 @@ export function ServerStatus() {
// features/tools owns installing; without it, fall back to the manual hint text.
const canInstall = !!getAction("tools.install");
const canConfigure = !!getAction("tools.languageServers");
const latestVersions = useToolUpdates((s) => s.latest);
// Installed servers with a newer version; the same tool can back several servers.
const updatable = canInstall ? servers.filter((s) => latestVersions[s.name]) : [];
if (!summary) return null;
return (
<>
@@ -40,6 +44,14 @@ export function ServerStatus() {
>
<span className={clsx(styles.dot, styles[summary.tone])} aria-hidden />
{summary.text}
{updatable.length > 0 && (
<Icon
name="arrow-up"
size={12}
className={styles.updateBadge}
label={tx("Language server updates are available")}
/>
)}
</BarButton>
<Popup
open={open}
@@ -56,6 +68,7 @@ export function ServerStatus() {
{servers.map((s) => {
// jdtls without a JDK new enough to run it: "Download JDK 25".
const [jdkFix] = s.status === "misconfigured" ? downloadJdkActions(s.message) : [];
const latest = latestVersions[s.name];
return (
<div key={s.id} className={styles.server}>
<div className={styles.line}>
@@ -81,6 +94,19 @@ export function ServerStatus() {
</Button>
) : (
<>
{latest && updatable.includes(s) && (
<Button
size="small"
aria-label={tx`Update ${s.name}`}
title={tx`Version ${latest} is available.`}
onClick={() => {
setOpen(false);
void executeAction("tools.install", s.name);
}}
>
<T>Update</T>
</Button>
)}
{s.status === "missing" && canInstall && (
<Button
size="small"
+44 -1
Переглянути файл
@@ -9,7 +9,17 @@ import {
} from "@/workbench/contributions";
import { useTasks } from "@/workbench/tasks";
import { MemoryToolsBackend, sampleTools, setToolsBackend } from "../backend";
import { cancelInstall, installTool, refreshTools, uninstallTool, useTools } from "../store";
import {
cancelInstall,
installTool,
loadToolUpdates,
publishToolUpdates,
refreshTools,
uninstallTool,
UPDATES_EVERY_MS,
useTools,
} from "../store";
import { useToolUpdates } from "@/workbench/contributions";
import { filterLanguages, groupByLanguage, LanguageServersPage } from "../LanguageServersPage";
import { installMissingServerPrompts, installServerWarningPrompts, missingKey, promptInstall } from "../missing";
import { resetTestForm, stagedFor, TestSettingsForm } from "./settingsForm";
@@ -41,6 +51,39 @@ beforeEach(() => {
afterEach(() => setToolsBackend(null));
describe("tool updates (#7365)", () => {
afterEach(() => localStorage.removeItem("openidea.tools.updates.v1"));
it("looks once a day, shows the last lookup meanwhile, and publishes it to the workbench", async () => {
let stop = publishToolUpdates();
backend.available = [{ name: "rust-analyzer", current: "1.0", latest: "1.1" }];
const updates = vi.spyOn(backend, "updates");
await loadToolUpdates(1_000);
expect(updates).toHaveBeenCalledTimes(1);
expect(useToolUpdates.getState().latest).toEqual({ "rust-analyzer": "1.1" });
// Another window starting within the day: the stored result, no lookup.
stop();
useTools.setState({ updates: {} });
useToolUpdates.setState({ latest: {} });
stop = publishToolUpdates();
const at = JSON.parse(localStorage.getItem("openidea.tools.updates.v1")!).at as number;
await loadToolUpdates(at + UPDATES_EVERY_MS - 1);
expect(updates).toHaveBeenCalledTimes(1);
expect(useToolUpdates.getState().latest).toEqual({ "rust-analyzer": "1.1" });
// Installing the update drops it, from the stored copy too.
await refreshTools();
await installTool("rust-analyzer");
expect(useToolUpdates.getState().latest).toEqual({});
expect(JSON.parse(localStorage.getItem("openidea.tools.updates.v1")!).updates).toEqual([]);
await loadToolUpdates(at + UPDATES_EVERY_MS);
expect(updates).toHaveBeenCalledTimes(2);
stop();
});
});
describe("tools store", () => {
it("installs, streams progress, restarts servers and notifies", async () => {
await refreshTools();
+19 -1
Переглянути файл
@@ -19,7 +19,23 @@ import { installCssModulesHint } from "./cssModules";
import { installXcodeBspHint } from "./xcodeBsp";
import { installStyledTemplatesHint } from "./styledTemplates";
import { activateSettingsPages } from "./settingsPages";
import { installTool, refreshTools, SETTINGS_PAGE_ID, toolByName, useTools } from "./store";
import {
installTool,
loadToolUpdates,
publishToolUpdates,
refreshTools,
SETTINGS_PAGE_ID,
toolByName,
useTools,
} from "./store";
/** After startup has settled: a lookup goes to every tool's registry. */
const UPDATES_DELAY_MS = 60_000;
function lookForToolUpdatesLater(): () => void {
const timer = setTimeout(() => void loadToolUpdates(), UPDATES_DELAY_MS);
return () => clearTimeout(timer);
}
export function activate(): () => void {
const disposers = [
@@ -80,6 +96,8 @@ export function activate(): () => void {
},
},
]),
publishToolUpdates(),
lookForToolUpdatesLater(),
installMissingServerPrompts(),
installServerReadyExpiry(),
installServerWarningPrompts(),
+56 -2
Переглянути файл
@@ -3,7 +3,7 @@ import { create } from "zustand";
import type { RequestId, ToolInfo, ToolUpdate } from "@/bindings";
import { executeAction } from "@/platform/actions";
import { isCancelled, nextRequestId } from "@/platform/ipc";
import { notifications } from "@/workbench/contributions";
import { notifications, useToolUpdates } from "@/workbench/contributions";
import { cancelTask, queueTask, upsertTask, useTasks } from "@/workbench/tasks";
import { toolsBackend } from "./backend";
import { tx } from "@/platform/i18n";
@@ -69,13 +69,67 @@ export function refreshTools(): Promise<void> {
let checkingUpdates: Promise<void> | null = null;
/** The last lookup's result, shared by the windows: `{ at, updates }`. */
const UPDATES_KEY = "openidea.tools.updates.v1";
/** How long a lookup stands before the next window start looks again (#7365). */
export const UPDATES_EVERY_MS = 24 * 60 * 60 * 1000;
interface CachedUpdates {
at: number;
updates: ToolUpdate[];
}
function cachedUpdates(): CachedUpdates | null {
try {
const cached = JSON.parse(localStorage.getItem(UPDATES_KEY) ?? "null") as CachedUpdates | null;
return cached && typeof cached.at === "number" && Array.isArray(cached.updates) ? cached : null;
} catch {
return null;
}
}
function saveUpdates(at: number, updates: Readonly<Record<string, ToolUpdate>>) {
try {
localStorage.setItem(UPDATES_KEY, JSON.stringify({ at, updates: Object.values(updates) }));
} catch {
// Storage full or unavailable: the next start looks again.
}
}
/**
* Shows the updates the last lookup found, and looks again when it is older than a day: the
* status bar's Language Servers says which servers have one without opening Settings.
*/
export function loadToolUpdates(now = Date.now()): Promise<void> {
const cached = cachedUpdates();
if (cached) useTools.setState({ updates: Object.fromEntries(cached.updates.map((u) => [u.name, u])) });
return cached && now - cached.at < UPDATES_EVERY_MS ? Promise.resolve() : checkToolUpdates();
}
/** Publishes the found updates to the workbench, and keeps the shared copy without installed ones. */
export function publishToolUpdates(): () => void {
const publish = (updates: Readonly<Record<string, ToolUpdate>>) =>
useToolUpdates.setState({
latest: Object.fromEntries(Object.values(updates).map((u) => [u.name, u.latest])),
});
publish(useTools.getState().updates);
return useTools.subscribe((s, prev) => {
if (s.updates === prev.updates) return;
publish(s.updates);
const cached = cachedUpdates();
if (cached) saveUpdates(cached.at, s.updates);
});
}
/** Looks for newer versions of the tools the IDE installed; offline, none are shown. */
export function checkToolUpdates(): Promise<void> {
checkingUpdates ??= (async () => {
useTools.setState({ checkingUpdates: true });
try {
const found = await toolsBackend().updates(nextRequestId());
useTools.setState({ updates: Object.fromEntries(found.map((u) => [u.name, u])) });
const updates = Object.fromEntries(found.map((u) => [u.name, u]));
saveUpdates(Date.now(), updates);
useTools.setState({ updates });
} catch {
// A failed lookup leaves the last result.
} finally {
+2 -1
Переглянути файл
@@ -11985,5 +11985,6 @@
"Product Name:": "产品名称:",
"Use letters, digits, spaces, hyphens and underscores, starting with a letter, digit or underscore": "只能使用字母、数字、空格、连字符和下划线,并以字母、数字或下划线开头",
"iOS": "iOS",
"macOS": "macOS"
"macOS": "macOS",
"Language server updates are available": "语言服务器有可用更新"
}
+6
Переглянути файл
@@ -242,6 +242,12 @@ export interface EditorDocumentLifecycle {
/** Bumped by `notifyTabTitlesChanged`; tab labels whose `title(input)` changed re-render. */
export const useEditorTabTitles = create<{ revision: number }>(() => ({ revision: 0 }));
/**
* The newer version of each installed language server or debugger that has one, by tool name:
* published by features/tools, shown where servers are listed (the status bar's Language Servers).
*/
export const useToolUpdates = create<{ latest: Readonly<Record<string, string>> }>(() => ({ latest: {} }));
/** An editor kind's tab title may have changed outside the tab state (e.g. a renamed agent task). */
export function notifyTabTitlesChanged() {
useEditorTabTitles.setState((s) => ({ revision: s.revision + 1 }));