From 4df4fc79ef110fb680943e98f41069463bcc44a0 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 6 Nov 2026 01:08:09 +0800 Subject: [PATCH] fix(lsp): keep rust-analyzer's developer notices out of notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A rust-analyzer built from source reports its own slow main-loop turns ("overly long loop turn took …") as error messages meant for its developers. They are logged now instead of shown as error notifications. --- crates/ide-lsp/src/handler.rs | 6 ++++++ crates/ide-lsp/tests/mock_server.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ide-lsp/src/handler.rs b/crates/ide-lsp/src/handler.rs index c8b8f9f0..17650b11 100644 --- a/crates/ide-lsp/src/handler.rs +++ b/crates/ide-lsp/src/handler.rs @@ -136,6 +136,12 @@ 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(); + // 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") { + tracing::warn!("[{}] {text}", self.server.name); + return; + } let level = match params.get("type").and_then(Value::as_u64) { Some(1) => NotifyLevel::Error, Some(2) => NotifyLevel::Warning, diff --git a/crates/ide-lsp/tests/mock_server.rs b/crates/ide-lsp/tests/mock_server.rs index c1cc65ff..8642c576 100644 --- a/crates/ide-lsp/tests/mock_server.rs +++ b/crates/ide-lsp/tests/mock_server.rs @@ -954,6 +954,11 @@ async fn apply_edit_hook_and_server_requests() { assert_eq!(v, Value::Null); assert!(peer.request::<_, Value>("unknown/method", Value::Null, None).await.is_err()); + peer.notify( + "window/showMessage", + json!({ "type": 1, "message": "overly long loop turn took 113ms (event handling took 95ms): PrimeCaches" }), + ) + .unwrap(); peer.notify("window/showMessage", json!({ "type": 2, "message": "careful" })).unwrap(); peer.notify("window/showMessage", json!({ "type": 3, "message": "info only" })).unwrap(); peer.notify("window/logMessage", json!({ "type": 1, "message": "log" })).unwrap(); @@ -962,7 +967,10 @@ async fn apply_edit_hook_and_server_requests() { }) .await; let notifies = h.events.lock().iter().filter(|e| matches!(e, IdeEvent::Notify { .. })).count(); - assert_eq!(notifies, 2, "showMessageRequest error + showMessage warning; info is not surfaced"); + assert_eq!( + notifies, 2, + "showMessageRequest error + showMessage warning; info and rust-analyzer's developer notices are not surfaced" + ); // Dynamically registered capability is now usable. s.respond(