@@ -216,7 +216,10 @@ impl MainLoop {
216216 self . run_with_progress :: < IndicatifReporter > ( db)
217217 }
218218
219- fn run_with_progress < R : Reporter > ( mut self , db : & mut ProjectDatabase ) -> Result < ExitStatus > {
219+ fn run_with_progress < R > ( mut self , db : & mut ProjectDatabase ) -> Result < ExitStatus >
220+ where
221+ R : Reporter + Default + ' static ,
222+ {
220223 self . sender . send ( MainLoopMessage :: CheckWorkspace ) . unwrap ( ) ;
221224
222225 let result = self . main_loop :: < R > ( db) ;
@@ -226,7 +229,10 @@ impl MainLoop {
226229 result
227230 }
228231
229- fn main_loop < R : Reporter > ( & mut self , db : & mut ProjectDatabase ) -> Result < ExitStatus > {
232+ fn main_loop < R > ( & mut self , db : & mut ProjectDatabase ) -> Result < ExitStatus >
233+ where
234+ R : Reporter + Default + ' static ,
235+ {
230236 // Schedule the first check.
231237 tracing:: debug!( "Starting main loop" ) ;
232238
@@ -237,12 +243,12 @@ impl MainLoop {
237243 MainLoopMessage :: CheckWorkspace => {
238244 let db = db. clone ( ) ;
239245 let sender = self . sender . clone ( ) ;
240- let reporter = R :: default ( ) ;
246+ let mut reporter = R :: default ( ) ;
241247
242248 // Spawn a new task that checks the project. This needs to be done in a separate thread
243249 // to prevent blocking the main loop here.
244250 rayon:: spawn ( move || {
245- match db. check ( & reporter) {
251+ match db. check_with_reporter ( & mut reporter) {
246252 Ok ( result) => {
247253 // Send the result back to the main loop for printing.
248254 sender
@@ -353,11 +359,12 @@ impl MainLoop {
353359}
354360
355361/// A progress reporter for `ty check`.
356- struct IndicatifReporter ( indicatif:: ProgressBar ) ;
362+ #[ derive( Default ) ]
363+ struct IndicatifReporter ( Option < indicatif:: ProgressBar > ) ;
357364
358- impl Default for IndicatifReporter {
359- fn default ( ) -> IndicatifReporter {
360- let progress = indicatif:: ProgressBar :: new ( 0 ) ;
365+ impl ty_project :: Reporter for IndicatifReporter {
366+ fn set_files ( & mut self , files : usize ) {
367+ let progress = indicatif:: ProgressBar :: new ( files as u64 ) ;
361368 progress. set_style (
362369 indicatif:: ProgressStyle :: with_template (
363370 "{msg:8.dim} {bar:60.green/dim} {pos}/{len} files" ,
@@ -366,17 +373,14 @@ impl Default for IndicatifReporter {
366373 . progress_chars ( "--" ) ,
367374 ) ;
368375 progress. set_message ( "Checking" ) ;
369- IndicatifReporter ( progress)
370- }
371- }
372376
373- impl ty_project:: Reporter for IndicatifReporter {
374- fn set_files ( & self , files : usize ) {
375- self . 0 . set_length ( files as u64 ) ;
377+ self . 0 = Some ( progress) ;
376378 }
377379
378380 fn report_file ( & self , _file : & ruff_db:: files:: File ) {
379- self . 0 . inc ( 1 ) ;
381+ if let Some ( ref progress_bar) = self . 0 {
382+ progress_bar. inc ( 1 ) ;
383+ }
380384 }
381385}
382386
0 commit comments