From 2e03fb34cb9efd3f287b9658a8d84df52ad660dd Mon Sep 17 00:00:00 2001 From: Mathias Fischler Date: Sat, 24 Jun 2023 14:18:21 +0200 Subject: Add infrastructure to enrich errors with hints (#1486) --- cli/src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/src/main.rs b/cli/src/main.rs index f8affa0d..af509a92 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -23,7 +23,7 @@ use std::cell::OnceCell; use termcolor::{ColorChoice, StandardStream, WriteColor}; use typst::diag::{bail, FileError, FileResult, SourceError, StrResult}; use typst::doc::Document; -use typst::eval::{Datetime, Library}; +use typst::eval::{eco_format, Datetime, Library}; use typst::font::{Font, FontBook, FontInfo, FontVariant}; use typst::geom::Color; use typst::syntax::{Source, SourceId}; @@ -436,6 +436,13 @@ fn print_diagnostics( let range = error.range(world); let diag = Diagnostic::error() .with_message(error.message) + .with_notes( + error + .hints + .iter() + .map(|e| (eco_format!("hint: {e}")).into()) + .collect(), + ) .with_labels(vec![Label::primary(error.span.source(), range)]); term::emit(&mut w, &config, world, &diag)?; -- cgit v1.2.3