From a4866b032391578beb970eddcc15f308e8eb8d11 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:32:49 +0800 Subject: [PATCH] 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. --- .../code-insight/ServerStatus.module.css | 6 ++ .../code-insight/ServerStatus.test.tsx | 29 +++++++++- src/features/code-insight/ServerStatus.tsx | 28 ++++++++- src/features/tools/__tests__/tools.test.tsx | 45 +++++++++++++- src/features/tools/index.ts | 20 ++++++- src/features/tools/store.ts | 58 ++++++++++++++++++- src/platform/locales/text/zh.json | 3 +- src/workbench/contributions.ts | 6 ++ 8 files changed, 188 insertions(+), 7 deletions(-) diff --git a/src/features/code-insight/ServerStatus.module.css b/src/features/code-insight/ServerStatus.module.css index d11c212c1..3082d9a11 100644 --- a/src/features/code-insight/ServerStatus.module.css +++ b/src/features/code-insight/ServerStatus.module.css @@ -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); +} diff --git a/src/features/code-insight/ServerStatus.test.tsx b/src/features/code-insight/ServerStatus.test.tsx index d32ee6b2c..ce3dfb64a 100644 --- a/src/features/code-insight/ServerStatus.test.tsx +++ b/src/features/code-insight/ServerStatus.test.tsx @@ -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(); + 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(); + 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) }); diff --git a/src/features/code-insight/ServerStatus.tsx b/src/features/code-insight/ServerStatus.tsx index be5bea54e..f90ff13f2 100644 --- a/src/features/code-insight/ServerStatus.tsx +++ b/src/features/code-insight/ServerStatus.tsx @@ -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() { > {summary.text} + {updatable.length > 0 && ( + + )} { // 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 (
@@ -81,6 +94,19 @@ export function ServerStatus() { ) : ( <> + {latest && updatable.includes(s) && ( + + )} {s.status === "missing" && canInstall && (