add medium rendering mode

just added it onto the short diagnostic rendering
otherwise big chunks of code would be duplicated
This commit is contained in:
Johann150
2020-07-15 20:04:30 +02:00
parent b2223d45b3
commit 12ab4dfce5
3 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -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),
}
}
+10
View File
@@ -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
+16 -1
View File
@@ -419,6 +419,7 @@ where
/// Output a short diagnostic, with a line number, severity, and message.
pub struct ShortDiagnostic<'diagnostic, FileId> {
diagnostic: &'diagnostic Diagnostic<FileId>,
show_notes: bool
}
impl<'diagnostic, FileId> ShortDiagnostic<'diagnostic, FileId>
@@ -427,8 +428,9 @@ where
{
pub fn new(
diagnostic: &'diagnostic Diagnostic<FileId>,
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(())
}
}