pub struct LineIndex { /* private fields */ }Expand description
A line-start table over one text snapshot.
Rebuild one per text revision (Document does this
automatically); conversions are then O(log lines) plus O(line length) for
the column walk.
§Examples
use increparse_lsp::{LineIndex, PositionEncoding};
use lsp_types::Position;
let text = "héllo\nwörld";
let index = LineIndex::new(text);
// "héllo" is 6 bytes / 5 UTF-16 units; end of line 0:
assert_eq!(
index.offset(text, Position::new(0, 5), PositionEncoding::Utf16),
Some(6)
);
assert_eq!(
index.position(text, 6, PositionEncoding::Utf16),
Position::new(0, 5)
);Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Number of lines (a trailing newline starts a final empty line).
Sourcepub fn line_start(&self, line: u32) -> Option<usize>
pub fn line_start(&self, line: u32) -> Option<usize>
Byte offset where line begins.
Sourcepub fn line_end(&self, text: &str, line: u32) -> Option<usize>
pub fn line_end(&self, text: &str, line: u32) -> Option<usize>
Byte offset just past the last byte of line, excluding the line
terminator.
Sourcepub fn offset(
&self,
text: &str,
position: Position,
encoding: PositionEncoding,
) -> Option<usize>
pub fn offset( &self, text: &str, position: Position, encoding: PositionEncoding, ) -> Option<usize>
Converts a Position to a byte offset.
Out-of-range lines clamp to the last line; overshooting columns clamp
to the end of the line (LSP clients legitimately send both while
typing). Returns None only if position.line overflows u32.
Trait Implementations§
impl Eq for LineIndex
impl StructuralPartialEq for LineIndex
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