Skip to content

Commit

Permalink
fix(diagnostics): don't output trailing blank line in display (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jun 1, 2024
1 parent 819e113 commit 8d1633f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,15 @@ fn print_diagnostic(
colors::yellow(format_args!(":{}:{}", line, column))
)?;
}
writeln!(io)?;

if diagnostic.snippet().is_some()
|| diagnostic.hint().is_some()
|| diagnostic.snippet_fixed().is_some()
|| !diagnostic.info().is_empty()
|| diagnostic.docs_url().is_some()
{
writeln!(io)?;
}

if let Some(snippet) = diagnostic.snippet() {
print_snippet(io, &snippet, max_line_number_digits)?;
Expand All @@ -366,22 +374,17 @@ fn print_diagnostic(
print_snippet(io, &snippet, max_line_number_digits)?;
}

writeln!(io)?;
if !diagnostic.info().is_empty() || diagnostic.docs_url().is_some() {
writeln!(io)?;
}

let mut needs_final_newline = false;
for info in diagnostic.info().iter() {
needs_final_newline = true;
writeln!(io, " {}: {}", colors::intense_blue("info"), info)?;
}
if let Some(docs_url) = diagnostic.docs_url() {
needs_final_newline = true;
writeln!(io, " {}: {}", colors::intense_blue("docs"), docs_url)?;
}

if needs_final_newline {
writeln!(io)?;
}

Ok(())
}

Expand Down

0 comments on commit 8d1633f

Please sign in to comment.