Skip to content

Commit 64ab6d4

Browse files
committed
Check pt fixing bugs
1 parent b6b7fc8 commit 64ab6d4

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

crates/cli/src/commands/analyze.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ fn display_analysis_summary(
344344

345345
let total_files = results.len();
346346
let total_lines: usize = results.iter().map(|r| r.line_count).sum();
347-
let total_functions: usize = results.iter().map(|_r| 0).sum(); // Would need to count functions from symbol table
347+
let total_functions: usize = results.iter().map(|r| {
348+
let stats = r.symbols.get_statistics();
349+
stats.function_count + stats.method_count
350+
}).sum();
348351

349352
term.write_line(&format!("Files analyzed: {}", total_files.to_string().bold()))?;
350353
term.write_line(&format!("Total lines: {}", total_lines.to_string().bold()))?;

crates/cli/src/output.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ impl OutputFormatter {
198198
html.push_str(&format!(" <h2>{}</h2>\n", html_escape(&result.file_path.to_string_lossy())));
199199
html.push_str(&format!(" <p><strong>Language:</strong> {:?}</p>\n", result.language));
200200
html.push_str(&format!(" <p><strong>Lines:</strong> {}</p>\n", result.line_count));
201-
html.push_str(&format!(" <p><strong>Functions:</strong> {}</p>\n", 0)); // Would need to count functions from symbol table
201+
let stats = result.symbols.get_statistics();
202+
html.push_str(&format!(" <p><strong>Functions:</strong> {}</p>\n", stats.function_count + stats.method_count));
202203
html.push_str(" </div>\n");
203204
}
204205

@@ -218,7 +219,8 @@ impl OutputFormatter {
218219
xml.push_str(&format!(" <path>{}</path>\n", xml_escape(&result.file_path.to_string_lossy())));
219220
xml.push_str(&format!(" <language>{:?}</language>\n", result.language));
220221
xml.push_str(&format!(" <lines>{}</lines>\n", result.line_count));
221-
xml.push_str(&format!(" <functions>{}</functions>\n", 0)); // Would need to count functions from symbol table
222+
let stats = result.symbols.get_statistics();
223+
xml.push_str(&format!(" <functions>{}</functions>\n", stats.function_count + stats.method_count));
222224
xml.push_str(" </file>\n");
223225
}
224226

@@ -256,8 +258,9 @@ impl OutputFormatter {
256258
md.push_str(&format!("## File {}: {}\n\n", index + 1, result.file_path.display()));
257259
md.push_str(&format!("- **Language**: {:?}\n", result.language));
258260
md.push_str(&format!("- **Lines of Code**: {}\n", result.line_count));
259-
md.push_str(&format!("- **Functions**: {}\n", 0)); // Would need to count functions from symbol table
260-
md.push_str(&format!("- **Variables**: {}\n", 0)); // Would need to count variables from symbol table
261+
let stats = result.symbols.get_statistics();
262+
md.push_str(&format!("- **Functions**: {}\n", stats.function_count + stats.method_count));
263+
md.push_str(&format!("- **Variables**: {}\n", stats.variable_count));
261264
md.push_str(&format!("- **Processing Time**: {}\n\n", Self::format_duration(result.processing_time)));
262265
}
263266

crates/parser/src/ast_builder.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ impl ASTBuilder {
172172
original_text: if text.len() <= self.config.max_text_length {
173173
text.to_string()
174174
} else {
175-
format!(
176-
"{}...",
177-
&text[..self.config.max_text_length.min(text.len())]
178-
)
175+
// Use Unicode-aware truncation to avoid panics on multi-byte characters
176+
let truncated = self.truncate_text_safely(text, self.config.max_text_length);
177+
format!("{}...", truncated)
179178
},
180179
attributes,
181180
}
@@ -479,6 +478,21 @@ impl ASTBuilder {
479478
}
480479
None
481480
}
481+
482+
/// Safely truncate text at Unicode character boundaries
483+
fn truncate_text_safely<'a>(&self, text: &'a str, max_bytes: usize) -> &'a str {
484+
if text.len() <= max_bytes {
485+
return text;
486+
}
487+
488+
// Find the largest valid UTF-8 boundary within max_bytes
489+
let mut boundary = max_bytes;
490+
while boundary > 0 && !text.is_char_boundary(boundary) {
491+
boundary -= 1;
492+
}
493+
494+
&text[..boundary]
495+
}
482496
}
483497

484498
/// Builder pattern for AST construction with fluent interface

0 commit comments

Comments
 (0)