diff options
Diffstat (limited to 'crates/typst-cli')
| -rw-r--r-- | crates/typst-cli/src/compile.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 4c4c24be..5ae569ba 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -8,8 +8,8 @@ use typst::diag::{bail, Severity, SourceDiagnostic, StrResult}; use typst::doc::Document; use typst::eval::{eco_format, Tracer}; use typst::geom::Color; -use typst::syntax::{FileId, Source}; -use typst::World; +use typst::syntax::{FileId, Source, Span}; +use typst::{World, WorldExt}; use crate::args::{CompileCommand, DiagnosticFormat, OutputFormat}; use crate::watch::Status; @@ -231,19 +231,16 @@ pub fn print_diagnostics( .map(|e| (eco_format!("hint: {e}")).into()) .collect(), ) - .with_labels(vec![Label::primary( - diagnostic.span.id(), - world.range(diagnostic.span), - )]); + .with_labels(label(world, diagnostic.span).into_iter().collect()); term::emit(&mut w, &config, world, &diag)?; // Stacktrace-like helper diagnostics. for point in &diagnostic.trace { let message = point.v.to_string(); - let help = Diagnostic::help().with_message(message).with_labels(vec![ - Label::primary(point.span.id(), world.range(point.span)), - ]); + let help = Diagnostic::help() + .with_message(message) + .with_labels(label(world, point.span).into_iter().collect()); term::emit(&mut w, &config, world, &help)?; } @@ -252,6 +249,11 @@ pub fn print_diagnostics( Ok(()) } +/// Create a label for a span. +fn label(world: &SystemWorld, span: Span) -> Option<Label<FileId>> { + Some(Label::primary(span.id()?, world.range(span)?)) +} + impl<'a> codespan_reporting::files::Files<'a> for SystemWorld { type FileId = FileId; type Name = String; |
