/** Status bar widget listing language servers, with a popup to restart or configure them. */ 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 { downloadJdkActions } from "@/platform/jdk"; import { relativePath, useProject } from "@/platform/project"; import { STATUS_LABEL, restartServer, servedByOther, serverLabel, serversSummary, useServers } from "./servers"; import styles from "./ServerStatus.module.css"; import { tx } from "@/platform/i18n"; export function ServerStatus() { const map = useServers((s) => s.servers); const servers = useMemo(() => [...map.values()].sort((a, b) => serverLabel(a).localeCompare(serverLabel(b))), [map]); const root = useProject((s) => s.project?.root ?? ""); const [open, setOpen] = useState(false); const ref = useRef(null); const summary = serversSummary(servers); // features/tools owns installing; without it, fall back to the manual hint text. const canInstall = !!getAction("tools.install"); const canConfigure = !!getAction("tools.languageServers"); if (!summary) return null; return ( <> setOpen((v) => !v)} > {summary.text} setOpen(false)} aria-label="Language servers" >
Language Servers
{servers.map((s) => { // jdtls without a JDK new enough to run it: "Download JDK 25". const [jdkFix] = s.status === "misconfigured" ? downloadJdkActions(s.message) : []; return (
{serverLabel(s)} {STATUS_LABEL[s.status]} {jdkFix ? ( ) : ( <> {s.status === "missing" && canInstall && ( )} {/* A missing server may have been installed outside the IDE since; restarting looks for it again. */} void restartServer(s.id)} /> )} {canConfigure && ( { setOpen(false); void executeAction("tools.languageServers", s.name); }} /> )}
{(s.languages.length > 0 || s.root) && (
{s.languages.join(", ")} {s.root && s.root !== root ? ` · ${relativePath(root, s.root) || s.root}` : ""}
)} {s.message && (
{s.message}
)}
); })}
); } function toneOf(status: string): "ok" | "busy" | "error" | "idle" { if (status === "ready") return "ok"; if (status === "starting" || status === "busy") return "busy"; if (status === "crashed" || status === "missing" || status === "misconfigured") return "error"; return "idle"; }