Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -358,8 +369,6 @@ impl<'a> DiagnosticRenderer<'a> {
);
}
}

out
}

fn render_json(&self, diag: &RichDiagnostic) -> String {
Expand Down
Loading