Skip to content

Commit

Permalink
Avoid empty diagnostic spans
Browse files Browse the repository at this point in the history
If the span is empty the column label will not be printed, which makes it hard to tell where the error is.
  • Loading branch information
mattfbacon committed Feb 16, 2024
1 parent dc78abf commit 6401265
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion worker/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6401265

Please sign in to comment.