diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 05567f8f579..b1d019cb113 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -734,7 +734,6 @@ impl fmt::Display for ConfigError { write!( f, "invalid config value{}:\n{}", - self.errors.len(), if self.errors.len() == 1 { "" } else { "s" }, errors ) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index d68e51240b7..9f4dc444020 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -75,6 +75,7 @@ pub(crate) struct GlobalState { pub(crate) flycheck: Arc<[FlycheckHandle]>, pub(crate) flycheck_sender: Sender, pub(crate) flycheck_receiver: Receiver, + pub(crate) last_flycheck_error: Option, // VFS pub(crate) loader: Handle, Receiver>, @@ -179,6 +180,7 @@ impl GlobalState { flycheck: Arc::from(Vec::new()), flycheck_sender, flycheck_receiver, + last_flycheck_error: None, vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))), vfs_config_version: 0, diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 481004988d3..7074ef018a1 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -169,7 +169,7 @@ pub(crate) fn handle_did_change_configuration( // Note that json can be null according to the spec if the client can't // provide a configuration. This is handled in Config::update below. let mut config = Config::clone(&*this.config); - config.update(json.take()); + this.config_errors = config.update(json.take()).err(); this.update_configuration(config); } } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 49595a45ea9..16d683957f0 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -602,21 +602,18 @@ impl GlobalState { (Progress::Begin, None) } flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)), - flycheck::Progress::DidCancel => (Progress::End, None), + flycheck::Progress::DidCancel => { + self.last_flycheck_error = None; + (Progress::End, None) + } flycheck::Progress::DidFailToRestart(err) => { - self.show_and_log_error( - "cargo check failed to start".to_string(), - Some(err), - ); + self.last_flycheck_error = + Some(format!("cargo check failed to start: {err}")); return; } flycheck::Progress::DidFinish(result) => { - if let Err(err) = result { - self.show_and_log_error( - "cargo check failed".to_string(), - Some(err.to_string()), - ); - } + self.last_flycheck_error = + result.err().map(|err| format!("cargo check failed to start: {err}")); (Progress::End, None) } }; diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 5300349e7d2..4e294855738 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -139,6 +139,11 @@ impl GlobalState { status.health = lsp_ext::Health::Warning; format_to!(message, "{err}\n"); } + if let Some(err) = &self.last_flycheck_error { + status.health = lsp_ext::Health::Warning; + message.push_str(err); + message.push('\n'); + } for ws in self.workspaces.iter() { let (ProjectWorkspace::Cargo { sysroot, .. }