@@ -9,7 +9,7 @@ use std::{
99use always_assert:: always;
1010use crossbeam_channel:: { select, Receiver } ;
1111use ide:: { FileId , PrimeCachesProgress } ;
12- use ide_db:: base_db:: VfsPath ;
12+ use ide_db:: base_db:: { SourceDatabaseExt , VfsPath } ;
1313use lsp_server:: { Connection , Notification , Request } ;
1414use lsp_types:: notification:: Notification as _;
1515use 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