From 12ab4dfce5ba2e1127202554011f761bae9c694d Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 15 Jul 2020 20:04:30 +0200 Subject: [PATCH] add medium rendering mode just added it onto the short diagnostic rendering otherwise big chunks of code would be duplicated --- codespan-reporting/src/term.rs | 3 ++- codespan-reporting/src/term/config.rs | 10 ++++++++++ codespan-reporting/src/term/views.rs | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/codespan-reporting/src/term.rs b/codespan-reporting/src/term.rs index c852e70..183676a 100644 --- a/codespan-reporting/src/term.rs +++ b/codespan-reporting/src/term.rs @@ -94,7 +94,8 @@ pub fn emit<'files, F: Files<'files>>( let mut renderer = Renderer::new(writer, config); match config.display_style { DisplayStyle::Rich => RichDiagnostic::new(diagnostic).render(files, &mut renderer), - DisplayStyle::Short => ShortDiagnostic::new(diagnostic).render(files, &mut renderer), + DisplayStyle::Medium => ShortDiagnostic::new(diagnostic, true).render(files, &mut renderer), + DisplayStyle::Short => ShortDiagnostic::new(diagnostic, false).render(files, &mut renderer), } } diff --git a/codespan-reporting/src/term/config.rs b/codespan-reporting/src/term/config.rs index cb368b3..18cbd44 100644 --- a/codespan-reporting/src/term/config.rs +++ b/codespan-reporting/src/term/config.rs @@ -59,6 +59,16 @@ pub enum DisplayStyle { /// /// ``` Rich, + /// Output a condensed diagnostic, with a line number, severity, message and notes (if any). + /// + /// ```text + /// test:2:9: error[E0001]: unexpected type in `+` application + /// = expected type `Int` + /// found type `String` + /// + /// error[E0002]: Bad config found + /// ``` + Medium, /// Output a short diagnostic, with a line number, severity, and message. /// /// ```text diff --git a/codespan-reporting/src/term/views.rs b/codespan-reporting/src/term/views.rs index 0e75977..5cc8168 100644 --- a/codespan-reporting/src/term/views.rs +++ b/codespan-reporting/src/term/views.rs @@ -419,6 +419,7 @@ where /// Output a short diagnostic, with a line number, severity, and message. pub struct ShortDiagnostic<'diagnostic, FileId> { diagnostic: &'diagnostic Diagnostic, + show_notes: bool } impl<'diagnostic, FileId> ShortDiagnostic<'diagnostic, FileId> @@ -427,8 +428,9 @@ where { pub fn new( diagnostic: &'diagnostic Diagnostic, + show_notes: bool, ) -> ShortDiagnostic<'diagnostic, FileId> { - ShortDiagnostic { diagnostic } + ShortDiagnostic { diagnostic, show_notes } } pub fn render<'files>( @@ -474,6 +476,19 @@ where )?; } + if self.show_notes { + // Additional notes + // + // ```text + // = expected type `Int` + // found type `String` + // ``` + for note in &self.diagnostic.notes { + renderer.render_snippet_note(0, note)?; + } + renderer.render_empty()?; + } + Ok(()) } }