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.

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].
utf8_char_len 🔒