pub struct LineIndex { /* private fields */ }Expand description
Maps between byte offsets and LSP Position (line, character).
LSP positions use zero-based line and UTF-16 code unit offsets. Our source strings use byte offsets. This struct pre-computes line start byte offsets for efficient bidirectional conversion.
Implementations§
Source§impl LineIndex
impl LineIndex
pub fn new(source: &str) -> Self
Sourcepub fn position(&self, byte_offset: usize) -> Position
pub fn position(&self, byte_offset: usize) -> Position
Convert a byte offset to an LSP Position.
Returns (line, character) where character is a UTF-16 code unit offset.
Sourcepub fn line_start_offset(&self, line: usize) -> usize
pub fn line_start_offset(&self, line: usize) -> usize
Return the byte offset of the start of line (0-indexed).
Returns source.len() if line is out of bounds.
Sourcepub fn utf16_length(&self, byte_start: usize, byte_end: usize) -> u32
pub fn utf16_length(&self, byte_start: usize, byte_end: usize) -> u32
Compute the UTF-16 length of a byte range in the source.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LineIndex
impl RefUnwindSafe for LineIndex
impl Send for LineIndex
impl Sync for LineIndex
impl Unpin for LineIndex
impl UnsafeUnpin for LineIndex
impl UnwindSafe for LineIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.