diff --git a/crates/ide-core/src/event.rs b/crates/ide-core/src/event.rs index 3cfd1acbb..976a018a1 100644 --- a/crates/ide-core/src/event.rs +++ b/crates/ide-core/src/event.rs @@ -118,6 +118,10 @@ pub enum IdeEvent { LanguageServer { server: ServerId, name: String, + /// What the user sees as the server when another program serves in its place. + #[serde(default)] + #[specta(optional)] + label: Option, status: ServerStatus, message: Option, }, diff --git a/crates/ide-language/src/lib.rs b/crates/ide-language/src/lib.rs index 90e70c64d..53979a14f 100644 --- a/crates/ide-language/src/lib.rs +++ b/crates/ide-language/src/lib.rs @@ -198,6 +198,10 @@ pub struct LanguageServerConfig { /// it parses a document. #[serde(default)] pub resync_on_configuration: bool, + /// Set by the settings hook: what the user sees as the server when another program serves + /// in its place (TypeScript 7's own `tsc --lsp` for vtsls). + #[serde(skip)] + pub display_name: Option, /// Set on plugin languages: start exactly this approved program. #[serde(skip)] pub pinned: Option, diff --git a/crates/ide-lsp/src/lib.rs b/crates/ide-lsp/src/lib.rs index bf5b43843..b047ee56f 100644 --- a/crates/ide-lsp/src/lib.rs +++ b/crates/ide-lsp/src/lib.rs @@ -3855,6 +3855,7 @@ impl LspManager { languages: s.languages(), status: s.status(), pid: s.running().and_then(|r| r.peer.pid()), + label: s.display_name(), }) .collect() } diff --git a/crates/ide-lsp/src/server.rs b/crates/ide-lsp/src/server.rs index dd1ebf9e2..f124b3197 100644 --- a/crates/ide-lsp/src/server.rs +++ b/crates/ide-lsp/src/server.rs @@ -213,6 +213,11 @@ impl Server { config } + /// The configured server's display name for the current (or last) instance. + pub fn display_name(&self) -> Option { + self.effective.lock().as_ref().and_then(|c| c.display_name.clone()) + } + pub fn set_effective_config(&self, generation: u64, config: LanguageServerConfig) { let st = self.state.lock(); if st.generation == generation && matches!(st.conn, Conn::Starting | Conn::Ready(_)) { @@ -507,7 +512,13 @@ impl Server { return; } *cur = (status, message.clone()); - st.events.push_back(IdeEvent::LanguageServer { server: self.id, name: self.name.clone(), status, message }); + st.events.push_back(IdeEvent::LanguageServer { + server: self.id, + name: self.name.clone(), + label: self.display_name(), + status, + message, + }); } fn queue_cleanup(&self, st: &mut State) { diff --git a/crates/ide-lsp/src/types.rs b/crates/ide-lsp/src/types.rs index 74fca5e8a..c78b114af 100644 --- a/crates/ide-lsp/src/types.rs +++ b/crates/ide-lsp/src/types.rs @@ -341,6 +341,10 @@ pub struct ServerInfo { pub status: ServerStatus, /// OS process of the running instance (for memory attribution). pub pid: Option, + /// What the user sees as the server when another program serves in its place. + #[serde(default)] + #[specta(optional)] + pub label: Option, } /// Read-only contents a language server provides for a non-`file:` URI diff --git a/crates/ide-lsp/tests/mock_server.rs b/crates/ide-lsp/tests/mock_server.rs index f906fb217..444f9bacb 100644 --- a/crates/ide-lsp/tests/mock_server.rs +++ b/crates/ide-lsp/tests/mock_server.rs @@ -268,6 +268,7 @@ fn server_cfg(name: &str) -> LanguageServerConfig { tsserver_project: false, tsserver_project_extras: Default::default(), resync_on_configuration: false, + display_name: None, pinned: None, } } diff --git a/crates/ide-lsp/tests/real_servers.rs b/crates/ide-lsp/tests/real_servers.rs index 1c0519387..7b1794455 100644 --- a/crates/ide-lsp/tests/real_servers.rs +++ b/crates/ide-lsp/tests/real_servers.rs @@ -426,6 +426,7 @@ async fn missing_binary_is_reported_with_install_hint() { tsserver_project: false, tsserver_project_extras: Default::default(), resync_on_configuration: false, + display_name: None, pinned: None, }; let (mgr, events) = manager(dir.path(), LanguageRegistry::from_configs(vec![lang("nope", "nope", server)])); @@ -698,6 +699,7 @@ async fn typescript_language_server_end_to_end() { tsserver_project: false, tsserver_project_extras: Default::default(), resync_on_configuration: false, + display_name: None, pinned: None, }; let (mgr, events) = manager(&root, LanguageRegistry::from_configs(vec![lang("typescript", "ts", server)])); @@ -750,6 +752,7 @@ fn npm_server(tools: &Path, name: &str, bin: &str, init: Option LanguageServerConfi tsserver_project: false, tsserver_project_extras: Default::default(), resync_on_configuration: false, + display_name: None, pinned: None, } } diff --git a/crates/ide-sdk/src/tests.rs b/crates/ide-sdk/src/tests.rs index aec194801..f7064ea7e 100644 --- a/crates/ide-sdk/src/tests.rs +++ b/crates/ide-sdk/src/tests.rs @@ -42,6 +42,7 @@ pub(crate) fn server(name: &str) -> LanguageServerConfig { tsserver_project: false, tsserver_project_extras: Default::default(), resync_on_configuration: false, + display_name: None, pinned: None, } } @@ -1429,6 +1430,7 @@ fn typescript_7_runs_its_own_language_server() { configure_server(&mut cfg, tmp.path(), tmp.path(), &s); assert_eq!(Path::new(&cfg.command), native, "{name}"); assert_eq!(cfg.args, ["--lsp", "--stdio"]); + assert_eq!(cfg.display_name.as_deref(), Some("TypeScript 7")); assert!(cfg.initialization_options.is_none()); } // Picked as a directory (its `lib`, as for older versions), too. diff --git a/src/bindings.ts b/src/bindings.ts index d999141b7..cfe8acb9f 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -6055,7 +6055,9 @@ cancellable: boolean } | /** Project indexing state changed (dumb mode on/off). */ { type: "indexState"; indexing: boolean; files: number; symbols: number } | /** Git status / branch information should be refreshed. */ -{ type: "vcsChanged"; root: IpcPath } | { type: "languageServer"; server: ServerId; name: string; status: ServerStatus; message: string | null } | +{ type: "vcsChanged"; root: IpcPath } | { type: "languageServer"; server: ServerId; name: string; +/** What the user sees as the server when another program serves in its place. */ +label?: string | null; status: ServerStatus; message: string | null } | /** A running server lacks a capability; the UI offers the managed tool as a replacement. */ { type: "languageServerWarning"; name: string; message: string; installTool: string } | /** @@ -9530,6 +9532,8 @@ export type ServerInfo = { status: ServerStatus, /** OS process of the running instance (for memory attribution). */ pid: number | null, + /** What the user sees as the server when another program serves in its place. */ + label?: string | null, }; export type ServerStatus = "starting" | "ready" | "busy" | "crashed" | "stopped" | "missing" | diff --git a/src/features/code-insight/ServerStatus.tsx b/src/features/code-insight/ServerStatus.tsx index 5a58cf41e..166575796 100644 --- a/src/features/code-insight/ServerStatus.tsx +++ b/src/features/code-insight/ServerStatus.tsx @@ -5,13 +5,13 @@ 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, serversSummary, useServers } from "./servers"; +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) => a.name.localeCompare(b.name)), [map]); + 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); @@ -56,7 +56,7 @@ export function ServerStatus() { )} aria-hidden /> - {s.name} + {serverLabel(s)} {STATUS_LABEL[s.status]} {jdkFix ? ( @@ -87,7 +87,7 @@ export function ServerStatus() { void restartServer(s.id)} /> diff --git a/src/features/code-insight/servers.test.ts b/src/features/code-insight/servers.test.ts index ec29d5da1..0f9b30688 100644 --- a/src/features/code-insight/servers.test.ts +++ b/src/features/code-insight/servers.test.ts @@ -71,6 +71,7 @@ describe("server status", () => { root: "/p", status: "ready", pid: null, + label: null, }); pending.splice(0).forEach((resolve) => resolve([info(11, "basedpyright"), info(12, "pyright")])); await vi.waitFor(() => expect(useServers.getState().servers.size).toBe(2)); @@ -78,7 +79,7 @@ describe("server status", () => { // The fallback stops and leaves the list; a snapshot taken before that answers late. const status = (id: number, name: string, status: ServerInfo["status"]) => - emitLocalIdeEvent({ type: "languageServer", server: id as ServerId, name, status, message: null }); + emitLocalIdeEvent({ type: "languageServer", server: id as ServerId, name, label: null, status, message: null }); status(13, "ty", "starting"); status(12, "pyright", "stopped"); emitLocalIdeEvent({ type: "languageServerRemoved", server: 12 as ServerId }); @@ -91,6 +92,30 @@ describe("server status", () => { expect(serversSummary([...useServers.getState().servers.values()])?.text).toBe("basedpyright"); }); + it("names a server by the program that serves in its place", () => { + useServers.setState({ servers: new Map() }); + dispose = installServerEvents(); + const id = 21 as ServerId; + emitLocalIdeEvent({ + type: "languageServer", + server: id, + name: "vtsls", + label: null, + status: "starting", + message: null, + }); + emitLocalIdeEvent({ + type: "languageServer", + server: id, + name: "vtsls", + label: "TypeScript 7", + status: "ready", + message: null, + }); + expect(useServers.getState().servers.get(id)).toMatchObject({ name: "vtsls", label: "TypeScript 7" }); + expect(serversSummary([...useServers.getState().servers.values()])?.text).toBe("TypeScript 7"); + }); + it("shows a running server busy only once it stays busy", async () => { vi.useFakeTimers(); try { diff --git a/src/features/code-insight/servers.ts b/src/features/code-insight/servers.ts index dce4c4335..819f8ad08 100644 --- a/src/features/code-insight/servers.ts +++ b/src/features/code-insight/servers.ts @@ -10,6 +10,8 @@ import { tx } from "@/platform/i18n"; export interface ServerEntry { id: ServerId; name: string; + /** What the user sees as the server when another program serves in its place (TypeScript 7 for vtsls). */ + label?: string | null; status: ServerStatus; message: string | null; languages: string[]; @@ -36,6 +38,11 @@ const removedAt = new Map(); export const BUSY_SHOW_DELAY_MS = 500; const pendingBusy = new Map>(); +/** The name shown for a server. */ +export function serverLabel(s: Pick): string { + return s.label ?? s.name; +} + function notifyMissing(e: ServerEntry) { if (notifiedMissing.has(e.name)) return; notifiedMissing.add(e.name); @@ -81,6 +88,7 @@ export async function refreshServers() { map.set(s.id, { id: s.id, name: s.name, + label: newer ? p.label : s.label, status: newer ? p.status : s.status, languages: s.languages, root: s.root, @@ -122,7 +130,7 @@ export function installServerEvents(): () => void { lastEvent.set(e.server, ++eventSeq); clearTimeout(pendingBusy.get(e.server)); pendingBusy.delete(e.server); - const entry = { id: e.server, name: e.name, status: e.status, message: e.message }; + const entry = { id: e.server, name: e.name, label: e.label, status: e.status, message: e.message }; if (e.status === "busy" && useServers.getState().servers.get(e.server)?.status === "ready") { pendingBusy.set( e.server, @@ -200,7 +208,7 @@ export function serversSummary( const tone = bad.length ? "error" : busy.length ? "busy" : servers.some((s) => s.status === "ready") ? "ok" : "idle"; // A stopped server (one a preferred server took over from) isn't worth naming next to running ones. const active = servers.filter((s) => s.status !== "stopped"); - const names = [...new Set((active.length ? active : servers).map((s) => s.name))]; + const names = [...new Set((active.length ? active : servers).map(serverLabel))]; const text = names.length === 1 ? names[0]! : `${names[0]} +${names.length - 1}`; return { text, tone }; }