From 8ed97244134d1a59f4c06f8729680922a2986962 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov <mail4score@gmail.com> Date: Sun, 11 Jul 2021 00:04:11 +0300 Subject: [PATCH] Do not erase Cargo diagnostics from the closed documents --- crates/rust-analyzer/src/main_loop.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 82a31362af6..b98827ae76e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -633,11 +633,9 @@ impl GlobalState { Ok(()) })? .on::<lsp_types::notification::DidCloseTextDocument>(|this, params| { - let mut version = None; if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { - match this.mem_docs.remove(&path) { - Some(doc) => version = Some(doc.version), - None => log::error!("orphan DidCloseTextDocument: {}", path), + if this.mem_docs.remove(&path).is_none() { + log::error!("orphan DidCloseTextDocument: {}", path); } this.semantic_tokens_cache.lock().remove(¶ms.text_document.uri); @@ -646,17 +644,6 @@ impl GlobalState { this.loader.handle.invalidate(path.to_path_buf()); } } - - // Clear the diagnostics for the previously known version of the file. - // This prevents stale "cargo check" diagnostics if the file is - // closed, "cargo check" is run and then the file is reopened. - this.send_notification::<lsp_types::notification::PublishDiagnostics>( - lsp_types::PublishDiagnosticsParams { - uri: params.text_document.uri, - diagnostics: Vec::new(), - version, - }, - ); Ok(()) })? .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {