Skip to main content

Module position

Module position 

Source
Expand description

Byte-offset ↔ LSP position conversion.

Bynk source spans are byte offsets into the UTF-8 source. LSP positions use UTF-16 code units (per the protocol’s default position encoding). For ASCII-only Bynk sources the two agree, but we go through code points to handle multi-byte characters correctly in identifiers and strings.

Structs§

PositionMap
A source snapshot paired with its precomputed LineIndex, so a request that maps many spans (semantic tokens, folding ranges, diagnostics, inlay hints, document symbols) pays the O(n) line-scan once and then converts each offset in O(log n) — closing the O(n²) blow-up of #732.

Functions§

end_position
The position one past the end of the source — used for “replace whole document” formatting edits.
offset_to_position
Convert a byte offset into the source string into an LSP position.
position_to_offset
Convert an LSP position into a byte offset. Returns None if the position is past the end of the source.
span_to_range
Convert a compiler Span into an LSP [Range].