@@ -6,12 +6,25 @@ use std::path::Path;
66use anyhow:: anyhow;
77use rustc_hash:: FxHashSet ;
88
9- use hir:: Crate ;
9+ use hir:: { db :: HirDatabase , Crate , Module } ;
1010use ide:: { DiagnosticsConfig , Severity } ;
1111use ide_db:: base_db:: SourceDatabaseExt ;
1212
1313use crate :: cli:: { load_cargo:: load_cargo, Result } ;
1414
15+ fn all_modules ( db : & dyn HirDatabase ) -> Vec < Module > {
16+ let mut worklist: Vec < _ > =
17+ Crate :: all ( db) . into_iter ( ) . map ( |krate| krate. root_module ( db) ) . collect ( ) ;
18+ let mut modules = Vec :: new ( ) ;
19+
20+ while let Some ( module) = worklist. pop ( ) {
21+ modules. push ( module) ;
22+ worklist. extend ( module. children ( db) ) ;
23+ }
24+
25+ modules
26+ }
27+
1528pub fn diagnostics ( path : & Path , load_output_dirs : bool , with_proc_macro : bool ) -> Result < ( ) > {
1629 let ( host, _vfs) = load_cargo ( path, load_output_dirs, with_proc_macro) ?;
1730 let db = host. raw_database ( ) ;
@@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -
2033 let mut found_error = false ;
2134 let mut visited_files = FxHashSet :: default ( ) ;
2235
23- let mut work = Vec :: new ( ) ;
24- let krates = Crate :: all ( db) ;
25- for krate in krates {
26- let module = krate. root_module ( db) ;
27- let file_id = module. definition_source ( db) . file_id ;
28- let file_id = file_id. original_file ( db) ;
36+ let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
37+ let file_id = module. definition_source ( db) . file_id . original_file ( db) ;
2938 let source_root = db. file_source_root ( file_id) ;
3039 let source_root = db. source_root ( source_root) ;
31- if !source_root. is_library {
32- work. push ( module) ;
33- }
34- }
40+ !source_root. is_library
41+ } ) ;
3542
3643 for module in work {
3744 let file_id = module. definition_source ( db) . file_id . original_file ( db) ;
0 commit comments