Skip to content

Commit 552aea5

Browse files
committed
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)
2 parents 14b9d18 + 116775b commit 552aea5

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,6 @@ impl GlobalState {
323323

324324
if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
325325
for file_id in diagnostic_changes {
326-
let db = self.analysis_host.raw_database();
327-
let source_root = db.file_source_root(file_id);
328-
if db.source_root(source_root).is_library {
329-
// Only publish diagnostics for files in the workspace, not from crates.io deps
330-
// or the sysroot.
331-
// While theoretically these should never have errors, we have quite a few false
332-
// positives particularly in the stdlib, and those diagnostics would stay around
333-
// forever if we emitted them here.
334-
continue;
335-
}
336-
337326
let uri = file_id_to_url(&self.vfs.read().0, file_id);
338327
let mut diagnostics =
339328
self.diagnostics.diagnostics_for(file_id).cloned().collect::<Vec<_>>();
@@ -972,10 +961,20 @@ impl GlobalState {
972961
}
973962

974963
fn update_diagnostics(&mut self) {
964+
let db = self.analysis_host.raw_database();
975965
let subscriptions = self
976966
.mem_docs
977967
.iter()
978968
.map(|path| self.vfs.read().0.file_id(path).unwrap())
969+
.filter(|&file_id| {
970+
let source_root = db.file_source_root(file_id);
971+
// Only publish diagnostics for files in the workspace, not from crates.io deps
972+
// or the sysroot.
973+
// While theoretically these should never have errors, we have quite a few false
974+
// positives particularly in the stdlib, and those diagnostics would stay around
975+
// forever if we emitted them here.
976+
!db.source_root(source_root).is_library
977+
})
979978
.collect::<Vec<_>>();
980979

981980
tracing::trace!("updating notifications for {:?}", subscriptions);

0 commit comments

Comments
 (0)