fix(lsp): show TypeScript 7 as the server when its own tsc --lsp runs (#3408)

A project on TypeScript 7 runs the compiler's native tsc --lsp in place of vtsls / typescript-language-server, but the status bar and the server popup still named the configured server. The settings hook gives such a server a display name, carried by ServerInfo and the languageServer event as an optional label; the server's name stays its identity.
This commit is contained in:
l0ng-ai
2026-11-15 00:25:51 +08:00
committed by GitHub
parent 3ec7daf845
commit 1a204b5f4b
13 changed files with 78 additions and 9 deletions
+4
View File
@@ -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<String>,
status: ServerStatus,
message: Option<String>,
},
+4
View File
@@ -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<String>,
/// Set on plugin languages: start exactly this approved program.
#[serde(skip)]
pub pinned: Option<ProgramPin>,
+1
View File
@@ -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()
}
+12 -1
View File
@@ -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<String> {
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) {
+4
View File
@@ -341,6 +341,10 @@ pub struct ServerInfo {
pub status: ServerStatus,
/// OS process of the running instance (for memory attribution).
pub pid: Option<u32>,
/// What the user sees as the server when another program serves in its place.
#[serde(default)]
#[specta(optional)]
pub label: Option<String>,
}
/// Read-only contents a language server provides for a non-`file:` URI
+1
View File
@@ -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,
}
}
+3
View File
@@ -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<serde_json::Valu
tsserver_project: false,
tsserver_project_extras: Default::default(),
resync_on_configuration: false,
display_name: None,
pinned: None,
}
}
+2
View File
@@ -1163,6 +1163,7 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root
{
cfg.command = native.to_string_lossy().into_owned();
cfg.args = vec!["--lsp".into(), "--stdio".into()];
cfg.display_name = Some("TypeScript 7".into());
cfg.initialization_options = None;
cfg.tsserver_project = false;
return;
@@ -1306,6 +1307,7 @@ fn custom_server(name: &str, ls: &LanguageServerSettings) -> LanguageServerConfi
tsserver_project: false,
tsserver_project_extras: Default::default(),
resync_on_configuration: false,
display_name: None,
pinned: None,
}
}
+2
View File
@@ -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.
+5 -1
View File
@@ -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" |
+4 -4
View File
@@ -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<HTMLButtonElement>(null);
@@ -56,7 +56,7 @@ export function ServerStatus() {
)}
aria-hidden
/>
<span className={styles.name}>{s.name}</span>
<span className={styles.name}>{serverLabel(s)}</span>
<span className={styles.status}>{STATUS_LABEL[s.status]}</span>
<span className={styles.spacer} />
{jdkFix ? (
@@ -87,7 +87,7 @@ export function ServerStatus() {
<IconButton
icon="refresh"
size="small"
title={s.status === "missing" ? tx`Check for ${s.name} again` : tx`Restart ${s.name}`}
title={s.status === "missing" ? tx`Check for ${s.name} again` : tx`Restart ${serverLabel(s)}`}
disabled={s.status === "starting"}
onClick={() => void restartServer(s.id)}
/>
+26 -1
View File
@@ -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 {
+10 -2
View File
@@ -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<ServerId, number>();
export const BUSY_SHOW_DELAY_MS = 500;
const pendingBusy = new Map<ServerId, ReturnType<typeof setTimeout>>();
/** The name shown for a server. */
export function serverLabel(s: Pick<ServerEntry, "name" | "label">): 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 };
}