mirror of
https://github.com/openharmony/third_party_rust_codespan.git
synced 2026-07-18 15:54:35 -04:00
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:
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user