Skip to content

Commit 8721b36

Browse files
Merge pull request #243 from Tcode-Motion/refactor-diagnostic-render-6491269308913055322
🧹 Refactor DiagnosticRenderer rendering logic
2 parents 0aa6d8e + ed9ffc9 commit 8721b36

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎cli/src/diagnostics.rs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ impl<'a> DiagnosticRenderer<'a> {
228228
String::new()
229229
};
230230

231+
self.render_header(&mut out, diag, &header);
232+
self.render_primary_span(&mut out, diag);
233+
self.render_footer(&mut out, diag);
234+
235+
out
236+
}
237+
238+
fn render_header(&self, out: &mut String, diag: &RichDiagnostic, header: &str) {
231239
if self.output == DiagnosticOutput::Colored {
232240
if header.is_empty() {
233241
let _ = write!(
@@ -258,8 +266,9 @@ impl<'a> DiagnosticRenderer<'a> {
258266
);
259267
}
260268
}
269+
}
261270

262-
// Primary span with source snippet
271+
fn render_primary_span(&self, out: &mut String, diag: &RichDiagnostic) {
263272
if let Some(primary) = &diag.primary_span {
264273
if let Some(file) = self.source_manager.get_file(primary.file_id) {
265274
let (line, col) = file.line_col(primary.span.start).unwrap_or((1, 1));
@@ -304,7 +313,9 @@ impl<'a> DiagnosticRenderer<'a> {
304313
}
305314
}
306315
}
316+
}
307317

318+
fn render_footer(&self, out: &mut String, diag: &RichDiagnostic) {
308319
// Related diagnostics (help, notes)
309320
for related in &diag.related {
310321
if self.output == DiagnosticOutput::Colored {
@@ -358,8 +369,6 @@ impl<'a> DiagnosticRenderer<'a> {
358369
);
359370
}
360371
}
361-
362-
out
363372
}
364373

365374
fn render_json(&self, diag: &RichDiagnostic) -> String {

0 commit comments

Comments
 (0)