From 29d5f29932eae4dcae589f2769e6a0f26c5ee4b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 12 Apr 2021 16:09:21 +0300 Subject: [PATCH] fix: don't spam repeated error messages when `cargo check` fails Conceptually, using a *message* here is wrong, because this is a "status", rather than "point in time" thing. But statuses are an LSP extension, while messages are stable. As a compromise, send message only for more critical `metadata` failures, and only once per state change. --- crates/rust-analyzer/src/reload.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index d0cc1b61a15..e51532d880f 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -100,10 +100,6 @@ fn is_interesting(path: &AbsPath, change_kind: ChangeKind) -> bool { } } pub(crate) fn report_new_status_if_needed(&mut self) { - if !self.config.server_status_notification() { - return; - } - let mut status = lsp_ext::ServerStatusParams { health: lsp_ext::Health::Ok, quiescent: self.is_quiescent(), @@ -129,7 +125,14 @@ pub(crate) fn report_new_status_if_needed(&mut self) { if self.last_reported_status.as_ref() != Some(&status) { self.last_reported_status = Some(status.clone()); - self.send_notification::(status); + + if let (lsp_ext::Health::Error, Some(message)) = (status.health, &status.message) { + self.show_message(lsp_types::MessageType::Error, message.clone()); + } + + if self.config.server_status_notification() { + self.send_notification::(status); + } } } @@ -225,7 +228,6 @@ pub(crate) fn switch_workspaces(&mut self) { if let Some(error_message) = self.fetch_workspace_error() { log::error!("failed to switch workspaces: {}", error_message); - self.show_message(lsp_types::MessageType::Error, error_message); if !self.workspaces.is_empty() { return; } @@ -233,7 +235,6 @@ pub(crate) fn switch_workspaces(&mut self) { if let Some(error_message) = self.build_data_error() { log::error!("failed to switch build data: {}", error_message); - self.show_message(lsp_types::MessageType::Error, error_message); } let workspaces = self