From ed9ffc90c9ee3728b13f6a78f17396b2362cd8d9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:08:11 +0000 Subject: [PATCH] Refactor `render_human` to extract logic into helper methods Split the `render_human` diagnostic method into smaller, targeted helper methods: `render_header`, `render_primary_span`, and `render_footer`. This improves readability, testing isolation, and maintainability without altering existing functionality. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- cli/src/diagnostics.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/src/diagnostics.rs b/cli/src/diagnostics.rs index a199fcef..b8b7609f 100644 --- a/cli/src/diagnostics.rs +++ b/cli/src/diagnostics.rs @@ -228,6 +228,14 @@ impl<'a> DiagnosticRenderer<'a> { String::new() }; + self.render_header(&mut out, diag, &header); + self.render_primary_span(&mut out, diag); + self.render_footer(&mut out, diag); + + out + } + + fn render_header(&self, out: &mut String, diag: &RichDiagnostic, header: &str) { if self.output == DiagnosticOutput::Colored { if header.is_empty() { let _ = write!( @@ -258,8 +266,9 @@ impl<'a> DiagnosticRenderer<'a> { ); } } + } - // Primary span with source snippet + fn render_primary_span(&self, out: &mut String, diag: &RichDiagnostic) { if let Some(primary) = &diag.primary_span { if let Some(file) = self.source_manager.get_file(primary.file_id) { let (line, col) = file.line_col(primary.span.start).unwrap_or((1, 1)); @@ -304,7 +313,9 @@ impl<'a> DiagnosticRenderer<'a> { } } } + } + fn render_footer(&self, out: &mut String, diag: &RichDiagnostic) { // Related diagnostics (help, notes) for related in &diag.related { if self.output == DiagnosticOutput::Colored { @@ -358,8 +369,6 @@ impl<'a> DiagnosticRenderer<'a> { ); } } - - out } fn render_json(&self, diag: &RichDiagnostic) -> String {