pub fn offset_to_byte(
line: &str,
offset: usize,
encoding: PositionEncoding,
) -> usizeExpand description
Map a position offset (in the given encoding) into a byte offset
into line, clamped to a char boundary.
PositionEncoding::Utf8/PositionEncoding::Utf16walk the line’s chars once accumulating the encoded length, bailing at the start of the char a mid-char offset would land in (the LSP behavior).PositionEncoding::Chartreatsoffsetas a character index and maps to the byte offset of that char, clamping past end-of-line to the line length (the #1289 WASM behavior).
The result is always a valid char boundary in line, so slicing
&line[..offset_to_byte(...)] never panics.