Parser (parse, incremental reparse from lutra_text edits), outline with UTF-16 ranges and short signatures, folding ranges, 8 MiB parse cap. Snapshot tests for five PHP 8.3 fixtures, proptests (random bytes, reparse equals fresh parse, undo round trip), ignored release timing test. Docs: architecture Syntax section, parity evidence, G4 note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
978 B
Rust
28 lines
978 B
Rust
//! Ranges in line and UTF-16 column coordinates.
|
|
|
|
use lutra_text::{Buffer, ColumnUnit, Position};
|
|
|
|
/// A range between two positions, end exclusive.
|
|
///
|
|
/// Lines and columns are zero-based; columns count UTF-16 code units, as
|
|
/// CodeMirror and LSP do.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
|
pub struct Range {
|
|
/// First position inside the range.
|
|
pub start: Position,
|
|
/// Position just after the range.
|
|
pub end: Position,
|
|
}
|
|
|
|
impl Range {
|
|
/// Converts the byte range `start..end` of `text` into a [`Range`].
|
|
///
|
|
/// Returns `None` when either offset is past the end of the text, inside
|
|
/// a character or inside a CRLF line break.
|
|
pub(crate) fn from_bytes(text: &Buffer, start: usize, end: usize) -> Option<Self> {
|
|
Some(Self {
|
|
start: text.offset_to_position(start, ColumnUnit::Utf16).ok()?,
|
|
end: text.offset_to_position(end, ColumnUnit::Utf16).ok()?,
|
|
})
|
|
}
|
|
}
|