From 79a3dd085c2e9b906c33a1ae1194449d02832036 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 21 Jul 2020 14:18:22 -0400 Subject: Clear diagnostics for known file version on close --- crates/rust-analyzer/src/main_loop.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 00ae6b900..d8d10ba99 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -432,19 +432,26 @@ impl GlobalState { Ok(()) })? .on::(|this, params| { + let mut version = None; if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { - if this.mem_docs.remove(&path).is_none() { - log::error!("orphan DidCloseTextDocument: {}", path) + match this.mem_docs.remove(&path) { + Some(entry) => version = entry, + None => log::error!("orphan DidCloseTextDocument: {}", path), } + if let Some(path) = path.as_path() { 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::PublishDiagnosticsParams { uri: params.text_document.uri, diagnostics: Vec::new(), - version: None, + version, }, ); Ok(()) -- cgit v1.2.3