@@ -6,12 +6,25 @@ use std::path::Path;
6
6
use anyhow:: anyhow;
7
7
use rustc_hash:: FxHashSet ;
8
8
9
- use hir:: Crate ;
9
+ use hir:: { db :: HirDatabase , Crate , Module } ;
10
10
use ide:: { DiagnosticsConfig , Severity } ;
11
11
use ide_db:: base_db:: SourceDatabaseExt ;
12
12
13
13
use crate :: cli:: { load_cargo:: load_cargo, Result } ;
14
14
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
+
15
28
pub fn diagnostics ( path : & Path , load_output_dirs : bool , with_proc_macro : bool ) -> Result < ( ) > {
16
29
let ( host, _vfs) = load_cargo ( path, load_output_dirs, with_proc_macro) ?;
17
30
let db = host. raw_database ( ) ;
@@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -
20
33
let mut found_error = false ;
21
34
let mut visited_files = FxHashSet :: default ( ) ;
22
35
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) ;
29
38
let source_root = db. file_source_root ( file_id) ;
30
39
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
+ } ) ;
35
42
36
43
for module in work {
37
44
let file_id = module. definition_source ( db) . file_id . original_file ( db) ;
0 commit comments