Skip to main content

offset_to_position

Function offset_to_position 

Source
pub fn offset_to_position(
    source: &str,
    line_starts: &[u32],
    offset: u32,
) -> Position
Expand description

Convert a byte offset into source to an LSP Position (0-based line/char).

Uses a precomputed line_starts table for O(log n) binary search. Handles both LF-only and CRLF line endings: a trailing \r before \n is not counted as a column so that positions are consistent regardless of line-ending style.