From 66af796c99868ff55d39cb47fb3e9c33024f120b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 6 May 2022 09:04:32 +0200 Subject: [PATCH] Render inner diagnostic with a renderer Previously diagnostics just had their StdError Display implementation called. This now uses a GraphicalReport if wished. --- src/handlers/graphical.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index 1ab09fa..a322a78 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -3,7 +3,7 @@ use std::fmt::{self, Write}; use owo_colors::{OwoColorize, Style}; use unicode_width::UnicodeWidthChar; -use crate::diagnostic_chain::DiagnosticChain; +use crate::diagnostic_chain::{DiagnosticChain, ErrorKind}; use crate::handlers::theme::*; use crate::protocol::{Diagnostic, Severity}; use crate::{LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents}; @@ -253,7 +253,21 @@ impl GraphicalReportHandler { let opts = textwrap::Options::new(width) .initial_indent(&initial_indent) .subsequent_indent(&rest_indent); - writeln!(f, "{}", textwrap::fill(&error.to_string(), opts))?; + match error { + ErrorKind::Diagnostic(diag) => { + let mut inner = String::new(); + + // Don't print footer for inner errors + let mut inner_renderer = self.clone(); + inner_renderer.footer = None; + inner_renderer.render_report(&mut inner, diag)?; + + writeln!(f, "{}", textwrap::fill(&inner, opts))?; + } + ErrorKind::StdError(err) => { + writeln!(f, "{}", textwrap::fill(&err.to_string(), opts))?; + } + } } }