Skip to content

Commit b8800fd

Browse files
Merge #9801
9801: fix: Don't publish diagnostics in crates.io or sysroot files r=jonas-schievink a=jonas-schievink Fixes #9766 bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents 40e9c97 + a310d74 commit b8800fd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use always_assert::always;
1010
use crossbeam_channel::{select, Receiver};
1111
use ide::{FileId, PrimeCachesProgress};
12-
use ide_db::base_db::VfsPath;
12+
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
1313
use lsp_server::{Connection, Notification, Request};
1414
use lsp_types::notification::Notification as _;
1515
use vfs::ChangeKind;
@@ -454,6 +454,17 @@ impl GlobalState {
454454

455455
if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
456456
for file_id in diagnostic_changes {
457+
let db = self.analysis_host.raw_database();
458+
let source_root = db.file_source_root(file_id);
459+
if db.source_root(source_root).is_library {
460+
// Only publish diagnostics for files in the workspace, not from crates.io deps
461+
// or the sysroot.
462+
// While theoretically these should never have errors, we have quite a few false
463+
// positives particularly in the stdlib, and those diagnostics would stay around
464+
// forever if we emitted them here.
465+
continue;
466+
}
467+
457468
let url = file_id_to_url(&self.vfs.read().0, file_id);
458469
let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
459470
let version = from_proto::vfs_path(&url)

0 commit comments

Comments
 (0)