@@ -21,24 +21,53 @@ impl CodeExtractor {
2121 self . extract_chunks_with_progress ( repo_path, _options, & NoOpProgressReporter )
2222 }
2323
24- pub fn extract_chunks_with_progress < P : ProgressReporter + ? Sized > (
24+ pub fn extract_chunks_with_progress < P : ProgressReporter > (
2525 & mut self ,
2626 repo_path : & Path ,
2727 _options : ExtractionOptions ,
2828 progress : & P ,
2929 ) -> Result < Vec < CodeChunk > > {
30- progress. set_phase ( " Scanning repository" . to_string ( ) ) ;
30+ progress. set_step ( crate :: game :: models :: loading_steps :: StepType :: Scanning ) ;
3131
32- // Use ignore crate to respect .gitignore files
32+ // First pass: count total files to process
33+ let walker_count = WalkBuilder :: new ( repo_path)
34+ . hidden ( false ) // Include hidden files
35+ . git_ignore ( true ) // Respect .gitignore
36+ . git_global ( true ) // Respect global gitignore
37+ . git_exclude ( true ) // Respect .git/info/exclude
38+ . build ( ) ;
39+
40+ let mut total_files_to_process = 0 ;
41+
42+ for entry in walker_count {
43+ let entry =
44+ entry. map_err ( |e| GitTypeError :: ExtractionFailed ( format ! ( "Walk error: {}" , e) ) ) ?;
45+ let path = entry. path ( ) ;
46+
47+ if !path. is_file ( ) {
48+ continue ;
49+ }
50+
51+ if let Some ( extension) = path. extension ( ) . and_then ( |e| e. to_str ( ) ) {
52+ if let Some ( _language) = Language :: from_extension ( extension) {
53+ if Self :: should_process_file_static ( path, & _options) {
54+ total_files_to_process += 1 ;
55+ }
56+ }
57+ }
58+ }
59+
60+ // Second pass: actually collect files with proper progress
3361 let walker = WalkBuilder :: new ( repo_path)
3462 . hidden ( false ) // Include hidden files
3563 . git_ignore ( true ) // Respect .gitignore
3664 . git_global ( true ) // Respect global gitignore
3765 . git_exclude ( true ) // Respect .git/info/exclude
3866 . build ( ) ;
3967
40- // Collect all files to process first to get total count
4168 let mut files_to_process = Vec :: new ( ) ;
69+ let mut processed_count = 0 ;
70+
4271 for entry in walker {
4372 let entry =
4473 entry. map_err ( |e| GitTypeError :: ExtractionFailed ( format ! ( "Walk error: {}" , e) ) ) ?;
@@ -52,13 +81,22 @@ impl CodeExtractor {
5281 if let Some ( language) = Language :: from_extension ( extension) {
5382 if Self :: should_process_file_static ( path, & _options) {
5483 files_to_process. push ( ( path. to_path_buf ( ) , language) ) ;
84+ processed_count += 1 ;
85+
86+ // Update progress with known total
87+ if processed_count % 10 == 0 || processed_count == total_files_to_process {
88+ progress. set_file_counts ( processed_count, total_files_to_process) ;
89+ }
5590 }
5691 }
5792 }
5893 }
5994
6095 let total_files = files_to_process. len ( ) ;
61- progress. set_phase ( "Parsing AST" . to_string ( ) ) ;
96+ progress. set_file_counts ( total_files, total_files) ;
97+ progress. set_progress ( 1.0 ) ; // Scanning completed
98+
99+ progress. set_step ( crate :: game:: models:: loading_steps:: StepType :: Extracting ) ;
62100
63101 // Process files in parallel with better progress tracking
64102 // Split files into smaller chunks for better progress visibility
@@ -68,7 +106,7 @@ impl CodeExtractor {
68106
69107 for chunk in files_to_process. chunks ( chunk_size) {
70108 // Process this chunk in parallel
71- let chunk_results: Result < Vec < Vec < CodeChunk > > > = chunk
109+ let chunk_results: Vec < Result < Vec < CodeChunk > > > = chunk
72110 . par_iter ( )
73111 . map ( |( path, language) | Self :: extract_from_file_static ( path, * language, & _options) )
74112 . collect ( ) ;
@@ -77,19 +115,29 @@ impl CodeExtractor {
77115 processed_files += chunk. len ( ) ;
78116 progress. set_file_counts ( processed_files, total_files) ;
79117
80- // Update spinner for each chunk to show progress
81- progress. update_spinner ( ) ;
118+ // Progress updates are now cheap - LoadingScreen controls rendering
82119
83- // Collect results
84- let chunk_results = chunk_results?;
85- for file_chunks in chunk_results {
86- all_chunks. extend ( file_chunks) ;
120+ // Collect results, skip failed files but continue processing
121+ for ( i, result) in chunk_results. into_iter ( ) . enumerate ( ) {
122+ match result {
123+ Ok ( file_chunks) => {
124+ all_chunks. extend ( file_chunks) ;
125+ }
126+ Err ( e) => {
127+ let file_path = & chunk[ i] . 0 ;
128+ eprintln ! (
129+ "Warning: Failed to extract from file {:?}: {}" ,
130+ file_path, e
131+ ) ;
132+ // Continue processing other files instead of crashing
133+ }
134+ }
87135 }
88136 }
89137
90138 progress. set_file_counts ( total_files, total_files) ;
91139 progress. set_current_file ( None ) ;
92- progress. set_phase ( " Finalizing" . to_string ( ) ) ;
140+ progress. set_step ( crate :: game :: models :: loading_steps :: StepType :: Finalizing ) ;
93141
94142 Ok ( all_chunks)
95143 }
0 commit comments