From 5410ace1fe0fb09fece7c61e23e6c70e9f742446 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 25 May 2022 15:47:41 +0200 Subject: [PATCH] fix: Clear native diagnostics for files when they are deleted --- crates/rust-analyzer/src/diagnostics.rs | 5 +++++ crates/rust-analyzer/src/global_state.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index 56b3afce98a33..202a01adf7108 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs @@ -40,6 +40,11 @@ impl DiagnosticCollection { self.changes.extend(self.check.drain().map(|(key, _value)| key)) } + pub(crate) fn clear_native_for(&mut self, file_id: FileId) { + self.native.remove(&file_id); + self.changes.insert(file_id); + } + pub(crate) fn add_check_diagnostic( &mut self, file_id: FileId, diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index d2b4fac5dc020..4af60035a20e0 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -201,6 +201,10 @@ impl GlobalState { } } + if !file.exists() { + self.diagnostics.clear_native_for(file.file_id); + } + let text = if file.exists() { let bytes = vfs.file_contents(file.file_id).to_vec(); String::from_utf8(bytes).ok().and_then(|text| {