about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-03-10 08:10:37 +0000
committerbors <bors@rust-lang.org>2023-03-10 08:10:37 +0000
commit552aea508d96a288999e7dd21a5fd7bfbb463048 (patch)
tree0fc8503b4c5aee42767b22190bf7f40253086fc6
parent14b9d182d54f22eade7afa644d105a18536c596e (diff)
parent116775bc83b65ed4c558633d0c9bec31f41b1454 (diff)
downloadrust-552aea508d96a288999e7dd21a5fd7bfbb463048.tar.gz
rust-552aea508d96a288999e7dd21a5fd7bfbb463048.zip
Auto merge of #14311 - Veykril:lib-diags, r=Veykril
internal: Don't attempt to calculate diagnostics in library crates

We already filtered these later on, but we might as well stop calculating them alltogether. This way we also show cargo diagnostics that occur outside of the workspace which can happen when something goes very wrong (and which usually then causes no check diagnostics to appear in the workspace at all)
-rw-r--r--crates/rust-analyzer/src/main_loop.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 60afb05bd64..43a0bf8ec05 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -323,17 +323,6 @@ impl GlobalState {
 
         if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
             for file_id in diagnostic_changes {
-                let db = self.analysis_host.raw_database();
-                let source_root = db.file_source_root(file_id);
-                if db.source_root(source_root).is_library {
-                    // Only publish diagnostics for files in the workspace, not from crates.io deps
-                    // or the sysroot.
-                    // While theoretically these should never have errors, we have quite a few false
-                    // positives particularly in the stdlib, and those diagnostics would stay around
-                    // forever if we emitted them here.
-                    continue;
-                }
-
                 let uri = file_id_to_url(&self.vfs.read().0, file_id);
                 let mut diagnostics =
                     self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
@@ -972,10 +961,20 @@ impl GlobalState {
     }
 
     fn update_diagnostics(&mut self) {
+        let db = self.analysis_host.raw_database();
         let subscriptions = self
             .mem_docs
             .iter()
             .map(|path| self.vfs.read().0.file_id(path).unwrap())
+            .filter(|&file_id| {
+                let source_root = db.file_source_root(file_id);
+                // Only publish diagnostics for files in the workspace, not from crates.io deps
+                // or the sysroot.
+                // While theoretically these should never have errors, we have quite a few false
+                // positives particularly in the stdlib, and those diagnostics would stay around
+                // forever if we emitted them here.
+                !db.source_root(source_root).is_library
+            })
             .collect::<Vec<_>>();
 
         tracing::trace!("updating notifications for {:?}", subscriptions);