@@ -9,7 +9,7 @@ use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Se
9
9
use ide_db:: { LineIndexDatabase , base_db:: SourceDatabase } ;
10
10
use load_cargo:: { LoadCargoConfig , ProcMacroServerChoice , load_workspace_at} ;
11
11
12
- use crate :: cli:: flags;
12
+ use crate :: cli:: { flags, progress_report :: ProgressReport } ;
13
13
14
14
impl flags:: Diagnostics {
15
15
pub fn run ( self ) -> anyhow:: Result < ( ) > {
@@ -50,23 +50,26 @@ impl flags::Diagnostics {
50
50
51
51
let mut found_error = false ;
52
52
let mut visited_files = FxHashSet :: default ( ) ;
53
-
54
- let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
55
- let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
56
- let source_root = db. file_source_root ( file_id. file_id ( db) ) . source_root_id ( db) ;
57
- let source_root = db. source_root ( source_root) . source_root ( db) ;
58
- !source_root. is_library
59
- } ) ;
60
-
53
+ let min_severity = self . severity . unwrap_or ( flags:: Severity :: Weak ) ;
54
+
55
+ let work = all_modules ( db)
56
+ . into_iter ( )
57
+ . filter ( |module| {
58
+ let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
59
+ let source_root = db. file_source_root ( file_id. file_id ( db) ) . source_root_id ( db) ;
60
+ let source_root = db. source_root ( source_root) . source_root ( db) ;
61
+ !source_root. is_library
62
+ } )
63
+ . collect :: < Vec < _ > > ( ) ;
64
+
65
+ let mut bar = ProgressReport :: new ( work. len ( ) ) ;
61
66
for module in work {
62
67
let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
63
68
if !visited_files. contains ( & file_id) {
69
+ let message = format ! ( "processing {}" , _vfs. file_path( file_id. file_id( db) ) ) ;
70
+ bar. set_message ( move || message. clone ( ) ) ;
64
71
let crate_name =
65
72
module. krate ( ) . display_name ( db) . as_deref ( ) . unwrap_or ( & sym:: unknown) . to_owned ( ) ;
66
- println ! (
67
- "processing crate: {crate_name}, module: {}" ,
68
- _vfs. file_path( file_id. file_id( db) )
69
- ) ;
70
73
for diagnostic in analysis
71
74
. full_diagnostics (
72
75
& DiagnosticsConfig :: test_sample ( ) ,
@@ -75,6 +78,16 @@ impl flags::Diagnostics {
75
78
)
76
79
. unwrap ( )
77
80
{
81
+ let severity = match diagnostic. severity {
82
+ Severity :: Error => flags:: Severity :: Error ,
83
+ Severity :: Warning => flags:: Severity :: Warning ,
84
+ Severity :: WeakWarning => flags:: Severity :: Weak ,
85
+ Severity :: Allow => continue ,
86
+ } ;
87
+ if severity < min_severity {
88
+ continue ;
89
+ }
90
+
78
91
if matches ! ( diagnostic. severity, Severity :: Error ) {
79
92
found_error = true ;
80
93
}
@@ -83,12 +96,17 @@ impl flags::Diagnostics {
83
96
let line_index = db. line_index ( range. file_id ) ;
84
97
let start = line_index. line_col ( range. range . start ( ) ) ;
85
98
let end = line_index. line_col ( range. range . end ( ) ) ;
86
- println ! ( "{severity:?} {code:?} from {start:?} to {end:?}: {message}" ) ;
99
+ bar. println ( format ! (
100
+ "at crate {crate_name}, file {}: {severity:?} {code:?} from {start:?} to {end:?}: {message}" ,
101
+ _vfs. file_path( file_id. file_id( db) )
102
+ ) ) ;
87
103
}
88
104
89
105
visited_files. insert ( file_id) ;
90
106
}
107
+ bar. inc ( 1 ) ;
91
108
}
109
+ bar. finish_and_clear ( ) ;
92
110
93
111
println ! ( ) ;
94
112
println ! ( "diagnostic scan complete" ) ;
0 commit comments