Expand description
UTF-8/UTF-16 position tracking, conversion, and span types.
This crate provides foundational types for source location tracking in the Perl LSP ecosystem:
ByteSpan: Byte-offset based spans for parser/AST useLineStartsCache: Efficient line index for offset-to-position conversionWirePosition/WireRange: LSP protocol-compatible position types
§Example
use perl_position_tracking::{ByteSpan, LineStartsCache};
let source = "line 1\nline 2\nline 3";
let cache = LineStartsCache::new(source);
// Create a span covering "line 2"
let span = ByteSpan::new(7, 13);
assert_eq!(span.slice(source), "line 2");
// Convert to line/column for LSP
let (line, col) = cache.offset_to_position(source, span.start);
assert_eq!(line, 1); // 0-indexed
assert_eq!(col, 0);Re-exports§
pub use mapper::LineEnding;pub use mapper::PositionMapper;pub use mapper::apply_edit_utf8;pub use mapper::json_to_position;pub use mapper::last_line_column_utf8;pub use mapper::newline_count;pub use mapper::position_to_json;
Modules§
- mapper
- Centralized position mapping for correct LSP position handling
Structs§
- Byte
Span - A byte-based span representing a range in source text.
- Line
Index - Stores line information for efficient position lookups, owning the text.
- Line
Starts Cache - Position
- A position in a source file with byte offset, line, and column
- Range
- A range in a source file defined by start and end positions
- Wire
Location - Wire
Position - Wire
Range
Functions§
Type Aliases§
- Source
Location - Type alias for backward compatibility with
SourceLocation.