Skip to main content

effective_error_span

Function effective_error_span 

Source
pub fn effective_error_span<L>(error_node: &SyntaxNode<L>) -> Range<usize>
where L: Language, L::Kind: TokenTrait,
Expand description

Returns the effective byte span of an error node.

Error nodes in the CST are zero-width: they sit at the byte position of the missing token but span no characters themselves. The effective span widens that point in both directions to include skippable tokens (whitespace / trivia) that immediately surround it — the “dead zone” between the adjacent real tokens. This gives callers a non-empty range suitable for highlighting.

Specifically the span is leading_gap_start..trailing_gap_end, where:

  • leading_gap_start is the end of the last non-skippable token before the error (or 0 if the error is at the start of the file).
  • trailing_gap_end is the start of the first non-skippable token at or after the error position (extended through any immediately following skippable tokens).

§Example

For input " <b> <c> }" with a missing {, the error node sits at byte 2 (after the two leading spaces are consumed as trivia by the Start step preceding the error). The effective span is 0..2, covering those two bytes.

For input "<a> <b> <c>" missing a trailing ., where the error appears at the end (byte 11) with no trailing whitespace, the span is 11..11 (zero-width).