aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs13
1 files changed, 10 insertions, 3 deletions
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 {
432 Ok(()) 432 Ok(())
433 })? 433 })?
434 .on::<lsp_types::notification::DidCloseTextDocument>(|this, params| { 434 .on::<lsp_types::notification::DidCloseTextDocument>(|this, params| {
435 let mut version = None;
435 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) { 436 if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
436 if this.mem_docs.remove(&path).is_none() { 437 match this.mem_docs.remove(&path) {
437 log::error!("orphan DidCloseTextDocument: {}", path) 438 Some(entry) => version = entry,
439 None => log::error!("orphan DidCloseTextDocument: {}", path),
438 } 440 }
441
439 if let Some(path) = path.as_path() { 442 if let Some(path) = path.as_path() {
440 this.loader.handle.invalidate(path.to_path_buf()); 443 this.loader.handle.invalidate(path.to_path_buf());
441 } 444 }
442 } 445 }
446
447 // Clear the diagnostics for the previously known version of the file.
448 // This prevents stale "cargo check" diagnostics if the file is
449 // closed, "cargo check" is run and then the file is reopened.
443 this.send_notification::<lsp_types::notification::PublishDiagnostics>( 450 this.send_notification::<lsp_types::notification::PublishDiagnostics>(
444 lsp_types::PublishDiagnosticsParams { 451 lsp_types::PublishDiagnosticsParams {
445 uri: params.text_document.uri, 452 uri: params.text_document.uri,
446 diagnostics: Vec::new(), 453 diagnostics: Vec::new(),
447 version: None, 454 version,
448 }, 455 },
449 ); 456 );
450 Ok(()) 457 Ok(())