perl-position-tracking
UTF-8/UTF-16 position tracking and conversion for the Perl LSP ecosystem.
Part of tree-sitter-perl-rs.
Public API
ByteSpan/SourceLocation-- byte-offset span for parser and AST nodesLineStartsCache-- line-start index for offset-to-position conversion (borrows text)LineIndex-- owning line index with UTF-16 column supportPositionMapper-- rope-backed mapper with incremental edit support and line-ending detectionWirePosition/WireRange/WireLocation-- LSP wire-protocol position typesPosition/Range-- engine types with 1-based line/column and byte offsetoffset_to_utf16_line_col/utf16_line_col_to_offset-- standalone conversion functionsLineEnding-- detected line-ending style (LF, CRLF, CR, Mixed)
Enable the lsp-compat feature for bidirectional From conversions with lsp_types.
Example
use ;
let source = "line 1\nline 2\nline 3";
let cache = new;
let span = new;
assert_eq!;
let = cache.offset_to_position;
assert_eq!; // 0-indexed line/UTF-16 column
License
MIT OR Apache-2.0