diff --git a/crates/ide-lsp/src/handler.rs b/crates/ide-lsp/src/handler.rs index 5e12df3e6e..7b79683fd7 100644 --- a/crates/ide-lsp/src/handler.rs +++ b/crates/ide-lsp/src/handler.rs @@ -513,6 +513,10 @@ impl ClientHandler { fn show_message(&self, mgr: &LspManager, params: &Value) { let text = params.get("message").and_then(Value::as_str).unwrap_or_default().to_owned(); + // "Renew or activate a license" doesn't apply to a free preview build: its status offers the update. + if self.expired_license(mgr, &text) { + return; + } // rust-analyzer built from source reports its own slow main-loop turns as errors, meant for // its developers (`poke_rust_analyzer_developer`); nothing for the user to act on. if text.starts_with("overly long loop turn") { @@ -534,6 +538,16 @@ impl ClientHandler { mgr.sink().emit(IdeEvent::Notify { level, title: self.server.name.clone(), body: Some(text) }); } + /// Whether `text` says the running build's license ran out; if so, its status says so. + fn expired_license(&self, mgr: &LspManager, text: &str) -> bool { + if !crate::server::reports_expired_license(text) { + return false; + } + tracing::warn!(server = ?self.server.id, generation = self.generation, "[{}] {text}", self.server.name); + self.server.report_expired_while_running(self.generation, mgr.sink()); + true + } + /// `window/showMessageRequest` expects `MessageActionItem | null`. Showing /// the question as a plain notification and replying null made Dart cancel /// renames with a warning (`Renamed field will be invisible in …`). @@ -770,6 +784,7 @@ impl Handler for ClientHandler { "window/showMessage" => self.show_message(&mgr, ¶ms), "window/logMessage" => { let text = params.get("message").and_then(Value::as_str).unwrap_or_default(); + self.expired_license(&mgr, text); if self.server.config.tsserver_project && tsserver_ran_out_of_memory(text) { tracing::warn!(server = ?self.server.id, generation = self.generation, "[{}] {text}", self.server.name); // The tasks of the dead tsserver never see their `end`: end them now diff --git a/crates/ide-lsp/src/server.rs b/crates/ide-lsp/src/server.rs index c3a21516bf..3b1f8c4f89 100644 --- a/crates/ide-lsp/src/server.rs +++ b/crates/ide-lsp/src/server.rs @@ -175,6 +175,9 @@ pub struct Server { /// Why the current instance's `initialize` failed, for the crash report. start_error: Mutex>, stderr: Mutex>, + /// The instance whose JetBrains preview build reported, while running, that its license + /// ran out: it stops serving after a short grace period, and only an update helps. + expired_while_running: Mutex>, pub progress: Mutex>, /// What the editor shows per path: the pushed and the pulled diagnostics together. diagnostics: Mutex>>, @@ -240,6 +243,7 @@ impl Server { started: Mutex::new(None), start_error: Mutex::new(None), stderr: Mutex::new(VecDeque::new()), + expired_while_running: Mutex::new(None), progress: Mutex::new(HashMap::new()), diagnostics: Mutex::new(HashMap::new()), pushed: Mutex::new(HashMap::new()), @@ -750,11 +754,35 @@ impl Server { return; } let busy = self.is_busy(); - self.queue_status(&mut st, if busy { ServerStatus::Busy } else { ServerStatus::Ready }, None); + let message = self.expired_message(st.generation); + self.queue_status(&mut st, if busy { ServerStatus::Busy } else { ServerStatus::Ready }, message); drop(st); self.publish(sink); } + /// A running JetBrains preview build (kotlin-lsp) said its license ran out: it keeps the + /// process alive but stops serving once a short grace period ends, without crashing. Its + /// status then says the build expired, which offers the update a crashed one gets. + pub fn report_expired_while_running(&self, generation: u64, sink: &SharedSink) { + let mut st = self.state.lock(); + if st.generation != generation || !matches!(st.conn, Conn::Ready(_)) { + return; + } + if self.expired_while_running.lock().replace(generation) == Some(generation) { + return; + } + let busy = self.is_busy(); + let message = self.expired_message(generation); + self.queue_status(&mut st, if busy { ServerStatus::Busy } else { ServerStatus::Ready }, message); + drop(st); + self.publish(sink); + } + + fn expired_message(&self, generation: u64) -> Option { + (*self.expired_while_running.lock() == Some(generation)) + .then(|| format!("This build of {} has expired and stops working soon; update it.", self.name)) + } + /// Whether the server reports work in progress (indexing, analysis). A task marked /// stuck stays visible but no longer holds the server busy. pub fn is_busy(&self) -> bool { @@ -1167,6 +1195,14 @@ fn is_expired_build_line(line: &str) -> bool { line.contains("This build of ") && line.contains(" has expired") } +/// What a running JetBrains preview build says once its date passes: "Your JetBrains license has +/// expired or is no longer valid. The language server keeps working for a short grace period…", +/// then a parked license gate. +pub(crate) fn reports_expired_license(text: &str) -> bool { + let text = text.to_ascii_lowercase(); + text.contains("jetbrains license has expired") || text.contains("license gate: parked") +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ide-lsp/tests/mock_server.rs b/crates/ide-lsp/tests/mock_server.rs index 53b5f15e81..8f04bce166 100644 --- a/crates/ide-lsp/tests/mock_server.rs +++ b/crates/ide-lsp/tests/mock_server.rs @@ -2094,6 +2094,28 @@ async fn apply_edit_hook_and_server_requests() { "showMessageRequest is now a question with actions, not a notification; info and developer notices are not surfaced" ); + // A JetBrains preview build past its date keeps running but stops serving after a grace + // period: its status says the build expired (the UI offers the update), once per instance. + let expired = |e: &IdeEvent| matches!(e, IdeEvent::LanguageServer { status: ide_core::event::ServerStatus::Ready | ide_core::event::ServerStatus::Busy, message: Some(m), .. } if m.contains("has expired")); + peer.notify( + "window/showMessage", + json!({ "type": 2, "message": "Your JetBrains license has expired or is no longer valid. The language server keeps working for a short grace period; renew or activate a license to avoid interruption." }), + ) + .unwrap(); + peer.notify( + "window/logMessage", + json!({ "type": 3, "message": "#LicenseManager - License gate: Parked(reason=GraceExpired)" }), + ) + .unwrap(); + peer.notify("window/showMessage", json!({ "type": 2, "message": "after" })).unwrap(); + eventually(|| h.events.lock().iter().any(|e| matches!(e, IdeEvent::Notify { body: Some(b), .. } if b == "after"))) + .await; + assert_eq!(h.events.lock().iter().filter(|e| expired(e)).count(), 1); + assert!( + !h.events.lock().iter().any(|e| matches!(e, IdeEvent::Notify { body: Some(b), .. } if b.contains("license"))), + "the license notice is not shown as is" + ); + // Dynamically registered capability is now usable. s.respond( "textDocument/documentHighlight", diff --git a/src/features/tools/__tests__/expired.test.ts b/src/features/tools/__tests__/expired.test.ts index fab6574202..930577f79a 100644 --- a/src/features/tools/__tests__/expired.test.ts +++ b/src/features/tools/__tests__/expired.test.ts @@ -11,7 +11,8 @@ vi.mock("../store", async (orig) => ({ installTool: store.installTool, })); -const { isExpiredBuild, promptUpdateExpired } = await import("../expired"); +const { installExpiredServerPrompts, isExpiredBuild, promptUpdateExpired } = await import("../expired"); +const { emitLocalIdeEvent } = await import("@/platform/ipc"); const { provideNotificationService } = await import("@/workbench/contributions"); type Note = Parameters[0]; @@ -67,4 +68,25 @@ describe("expired language server builds", () => { await promptUpdateExpired("kotlin-lsp"); expect(notes.at(-1)!.actions?.map((a) => a.label)).toEqual(["Language Servers…"]); }); + + it("ask once when a running build reports that it expired", async () => { + store.tool = { ...KOTLIN, status: "installed" }; + const off = installExpiredServerPrompts(); + const message = "This build of kotlin-lsp has expired and stops working soon; update it."; + const status = (status: "ready" | "busy" | "starting", msg: string | null) => + emitLocalIdeEvent({ type: "languageServer", server: 4, name: "kotlin-lsp", status, message: msg }); + status("ready", null); + status("busy", message); + status("ready", message); + await vi.waitFor(() => expect(notes).toHaveLength(1)); + expect(notes[0]!.body).toBe( + "This build of Kotlin LSP (JetBrains) has expired and stops working soon. Update it to the latest release?", + ); + expect(notes[0]!.actions?.map((a) => a.label)).toEqual(["Update", "Language Servers…"]); + // A restarted instance asks again. + status("starting", null); + status("ready", message); + await vi.waitFor(() => expect(notes).toHaveLength(2)); + off(); + }); }); diff --git a/src/features/tools/expired.ts b/src/features/tools/expired.ts index a8b0a64829..ad88f8f2af 100644 --- a/src/features/tools/expired.ts +++ b/src/features/tools/expired.ts @@ -1,6 +1,7 @@ /** * "kotlin-lsp has expired — Update": JetBrains preview builds stop starting once their date - * passes, and the backend then stops restarting them. Offer the latest release instead. + * passes, and the backend then stops restarting them. One already running keeps its process but + * stops serving after a short grace period; its status says so. Offer the latest release instead. * A managed copy comes before `PATH` (Homebrew), so installing it also replaces one found there. */ import { executeAction } from "@/platform/actions"; @@ -13,7 +14,8 @@ export const isExpiredBuild = (message: string | null) => !!message && /This bui export const expiredKey = (name: string) => `lsp-expired-${name}`; -export async function promptUpdateExpired(name: string) { +/** `running`: the build expired while running, so it still serves for a short while. */ +export async function promptUpdateExpired(name: string, running = false) { await refreshTools(); const tool = toolByName(name); const display = tool?.displayName ?? name; @@ -23,11 +25,17 @@ export async function promptUpdateExpired(name: string) { group: "lsp", level: "warning", title: tx`${display} has expired`, - body: !installable - ? tx`This build of ${display} no longer starts. Choose a newer build in Language Servers.` - : tool.status === "installed" - ? tx`This build of ${display} no longer starts. Update it to the latest release?` - : tx`This build of ${display} no longer starts. Install the latest release for the IDE? It is used instead of ${tool.path ?? tool.command}.`, + body: running + ? !installable + ? tx`This build of ${display} has expired and stops working soon. Choose a newer build in Language Servers.` + : tool.status === "installed" + ? tx`This build of ${display} has expired and stops working soon. Update it to the latest release?` + : tx`This build of ${display} has expired and stops working soon. Install the latest release for the IDE? It is used instead of ${tool.path ?? tool.command}.` + : !installable + ? tx`This build of ${display} no longer starts. Choose a newer build in Language Servers.` + : tool.status === "installed" + ? tx`This build of ${display} no longer starts. Update it to the latest release?` + : tx`This build of ${display} no longer starts. Install the latest release for the IDE? It is used instead of ${tool.path ?? tool.command}.`, key, sticky: true, actions: [ @@ -45,7 +53,15 @@ export async function promptUpdateExpired(name: string) { } export function installExpiredServerPrompts(): () => void { + // A running instance's status repeats its message on every Ready ⇄ Busy change: ask once. + const asked = new Set(); return onIdeEvent("languageServer", (e) => { - if (e.status === "crashed" && isExpiredBuild(e.message)) void promptUpdateExpired(e.name); + if (e.status === "starting") asked.delete(e.server); + if (!isExpiredBuild(e.message)) return; + if (e.status === "crashed") void promptUpdateExpired(e.name); + else if ((e.status === "ready" || e.status === "busy") && !asked.has(e.server)) { + asked.add(e.server); + void promptUpdateExpired(e.name, true); + } }); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 7b1ce6da57..a9d509ae31 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -5661,5 +5661,8 @@ "Changelist:": "Changelist:", "Clone Sources": "Clone Sources", "Could not load the {label} icon": "Could not load the {label} icon", - "plugin {pluginId}: {e}": "plugin {pluginId}: {e}" + "plugin {pluginId}: {e}": "plugin {pluginId}: {e}", + "This build of {display} has expired and stops working soon. Choose a newer build in Language Servers.": "This build of {display} has expired and stops working soon. Choose a newer build in Language Servers.", + "This build of {display} has expired and stops working soon. Update it to the latest release?": "This build of {display} has expired and stops working soon. Update it to the latest release?", + "This build of {display} has expired and stops working soon. Install the latest release for the IDE? It is used instead of {path}.": "This build of {display} has expired and stops working soon. Install the latest release for the IDE? It is used instead of {path}." } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index f9502afd60..fc561e9285 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -12564,5 +12564,8 @@ "Included changes": "包含的更改", "Clone Sources": "克隆来源", "Could not load the {label} icon": "无法加载 {label} 图标", - "plugin {pluginId}: {e}": "插件 {pluginId}:{e}" + "plugin {pluginId}: {e}": "插件 {pluginId}:{e}", + "This build of {display} has expired and stops working soon. Choose a newer build in Language Servers.": "此版本的 {display} 已过期,很快将停止工作。请在“语言服务器”中选择更新的版本。", + "This build of {display} has expired and stops working soon. Update it to the latest release?": "此版本的 {display} 已过期,很快将停止工作。要更新到最新版本吗?", + "This build of {display} has expired and stops working soon. Install the latest release for the IDE? It is used instead of {path}.": "此版本的 {display} 已过期,很快将停止工作。要为 IDE 安装最新版本吗?安装后将代替 {path} 使用。" }