@@ -9,7 +9,7 @@ use std::{
9
9
use always_assert:: always;
10
10
use crossbeam_channel:: { select, Receiver } ;
11
11
use ide:: { FileId , PrimeCachesProgress } ;
12
- use ide_db:: base_db:: VfsPath ;
12
+ use ide_db:: base_db:: { SourceDatabaseExt , VfsPath } ;
13
13
use lsp_server:: { Connection , Notification , Request } ;
14
14
use lsp_types:: notification:: Notification as _;
15
15
use vfs:: ChangeKind ;
@@ -454,6 +454,17 @@ impl GlobalState {
454
454
455
455
if let Some ( diagnostic_changes) = self . diagnostics . take_changes ( ) {
456
456
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
+
457
468
let url = file_id_to_url ( & self . vfs . read ( ) . 0 , file_id) ;
458
469
let diagnostics = self . diagnostics . diagnostics_for ( file_id) . cloned ( ) . collect ( ) ;
459
470
let version = from_proto:: vfs_path ( & url)
0 commit comments