mirror of https://github.com/zkat/miette.git
refactor: move detail rendering out for clarity
This commit is contained in:
parent
3ad7666777
commit
f8cf66cd90
|
|
@ -9,6 +9,39 @@ use crate::protocol::{Diagnostic, DiagnosticDetail, DiagnosticReporter, Severity
|
||||||
|
|
||||||
pub struct Reporter;
|
pub struct Reporter;
|
||||||
|
|
||||||
|
impl Reporter {
|
||||||
|
fn render_detail(
|
||||||
|
&self,
|
||||||
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
|
detail: &DiagnosticDetail,
|
||||||
|
) -> core::fmt::Result {
|
||||||
|
use core::fmt::Write as _;
|
||||||
|
write!(f, "\n[{}]", detail.source_name)?;
|
||||||
|
if let Some(msg) = &detail.message {
|
||||||
|
write!(f, " {}:", msg)?;
|
||||||
|
}
|
||||||
|
writeln!(
|
||||||
|
indented(f),
|
||||||
|
"\n\n({}) @ line {}, col {} ",
|
||||||
|
detail.span.label,
|
||||||
|
detail.span.start.line + 1,
|
||||||
|
detail.span.start.column + 1
|
||||||
|
)?;
|
||||||
|
if let Some(other_spans) = &detail.other_spans {
|
||||||
|
for span in other_spans {
|
||||||
|
writeln!(
|
||||||
|
indented(f),
|
||||||
|
"\n{} @ line {}, col {} ",
|
||||||
|
span.label,
|
||||||
|
span.start.line + 1,
|
||||||
|
span.start.column + 1
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl DiagnosticReporter for Reporter {
|
impl DiagnosticReporter for Reporter {
|
||||||
fn debug(
|
fn debug(
|
||||||
&self,
|
&self,
|
||||||
|
|
@ -44,36 +77,8 @@ impl DiagnosticReporter for Reporter {
|
||||||
|
|
||||||
if let Some(details) = diagnostic.details() {
|
if let Some(details) = diagnostic.details() {
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
for DiagnosticDetail {
|
for detail in details {
|
||||||
source_name,
|
self.render_detail(f, detail)?;
|
||||||
message,
|
|
||||||
span,
|
|
||||||
other_spans,
|
|
||||||
..
|
|
||||||
} in details
|
|
||||||
{
|
|
||||||
write!(f, "\n[{}]", source_name)?;
|
|
||||||
if let Some(msg) = message {
|
|
||||||
write!(f, " {}:", msg)?;
|
|
||||||
}
|
|
||||||
writeln!(
|
|
||||||
indented(f),
|
|
||||||
"\n\n({}) @ line {}, col {} ",
|
|
||||||
span.label,
|
|
||||||
span.start.line + 1,
|
|
||||||
span.start.column + 1
|
|
||||||
)?;
|
|
||||||
if let Some(other_spans) = other_spans {
|
|
||||||
for span in other_spans {
|
|
||||||
writeln!(
|
|
||||||
indented(f),
|
|
||||||
"\n{} @ line {}, col {} ",
|
|
||||||
span.label,
|
|
||||||
span.start.line + 1,
|
|
||||||
span.start.column + 1
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue