Skip to main content

Crate perl_position_tracking

Crate perl_position_tracking 

Source
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:

§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§

ByteSpan
A byte-based span representing a range in source text.
LineIndex
Stores line information for efficient position lookups, owning the text.
LineStartsCache
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
WireLocation
WirePosition
WireRange

Functions§

offset_to_utf16_line_col
utf16_line_col_to_offset

Type Aliases§

SourceLocation
Type alias for backward compatibility with SourceLocation.