pub struct LineIndex { /* private fields */ }Expand description
Line-start table over the original source.
Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn line_col(&self, offset: TextSize) -> LineCol
pub fn line_col(&self, offset: TextSize) -> LineCol
Convert a byte offset to 0-based line/column (UTF-8).
If offset falls inside a multi-byte character the result reports
the mechanical byte-offset within the line — callers that need
char-aligned columns are responsible for snapping.
§Panics
Panics if the computed line index does not fit in u32, which
requires a source file with more than u32::MAX lines — impossible
for any input that also fits in a TextSize.
Sourcepub fn to_utf16(&self, pos: LineCol) -> WideLineCol
pub fn to_utf16(&self, pos: LineCol) -> WideLineCol
Convert a LineCol (UTF-8) to the LSP UTF-16 flavour.
Sourcepub fn from_utf16(&self, pos: WideLineCol) -> LineCol
pub fn from_utf16(&self, pos: WideLineCol) -> LineCol
Convert an LSP UTF-16 position back to a UTF-8 byte LineCol.
Sourcepub fn line_range(&self, line: u32) -> Option<TextRange>
pub fn line_range(&self, line: u32) -> Option<TextRange>
Range of the given 0-based line in full-source byte offsets.
Includes the trailing \n if the line has one. Returns None for
lines past the end.
For the final line of the input (which has no trailing newline in
the index) the range extends to TextSize::from(u32::MAX) as a
sentinel end — callers that care about the “real” tail should clamp
to the input length.
Sourcepub fn line_count(&self) -> u32
pub fn line_count(&self) -> u32
Number of lines in the input. Always >= 1; empty input has a
single empty line.