@@ -9,7 +9,7 @@ use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Se
99use ide_db:: { LineIndexDatabase , base_db:: SourceDatabase } ;
1010use load_cargo:: { LoadCargoConfig , ProcMacroServerChoice , load_workspace_at} ;
1111
12- use crate :: cli:: flags;
12+ use crate :: cli:: { flags, progress_report :: ProgressReport } ;
1313
1414impl flags:: Diagnostics {
1515 pub fn run ( self ) -> anyhow:: Result < ( ) > {
@@ -50,23 +50,26 @@ impl flags::Diagnostics {
5050
5151 let mut found_error = false ;
5252 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 ( ) ) ;
6166 for module in work {
6267 let file_id = module. definition_source_file_id ( db) . original_file ( db) ;
6368 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 ( ) ) ;
6471 let crate_name =
6572 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- ) ;
7073 for diagnostic in analysis
7174 . full_diagnostics (
7275 & DiagnosticsConfig :: test_sample ( ) ,
@@ -75,6 +78,16 @@ impl flags::Diagnostics {
7578 )
7679 . unwrap ( )
7780 {
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+
7891 if matches ! ( diagnostic. severity, Severity :: Error ) {
7992 found_error = true ;
8093 }
@@ -83,12 +96,17 @@ impl flags::Diagnostics {
8396 let line_index = db. line_index ( range. file_id ) ;
8497 let start = line_index. line_col ( range. range . start ( ) ) ;
8598 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+ ) ) ;
87103 }
88104
89105 visited_files. insert ( file_id) ;
90106 }
107+ bar. inc ( 1 ) ;
91108 }
109+ bar. finish_and_clear ( ) ;
92110
93111 println ! ( ) ;
94112 println ! ( "diagnostic scan complete" ) ;
0 commit comments