From 64012652b6648b27201ac207779bee9c4b87d5ab Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Fri, 16 Feb 2024 00:39:33 -0800 Subject: [PATCH] Avoid empty diagnostic spans If the span is empty the column label will not be printed, which makes it hard to tell where the error is. --- worker/src/diagnostic.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/worker/src/diagnostic.rs b/worker/src/diagnostic.rs index 8997c5b..8d73d5d 100644 --- a/worker/src/diagnostic.rs +++ b/worker/src/diagnostic.rs @@ -214,8 +214,12 @@ pub fn format_diagnostics(sandbox: &WithSource, diagnostics: &[SourceDiagnostic] .source(file_id) .expect("invalid file ID in diagnostic span"); let byte_span = source.range(typst_span).unwrap(); - let char_span = byte_span_to_char_span(source.text(), byte_span) + let mut char_span = byte_span_to_char_span(source.text(), byte_span) .expect("invalid byte span reported by typst diagnostic"); + // Avoid empty spans. + if char_span.end == char_span.start { + char_span.end += 1; + } Span { file_id, char_span_start: char_span.start,