pub struct LineIndex { /* private fields */ }Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
The bytes this index itself holds — one offset per line plus one byte per line.
Asked by the analysis’s memory report (cpp_code_analysis::MemoryReport): a VFS entry is text and an index,
and a report that counted only the text would blame the wrong half on a project of many small files.
pub fn parse(text: &str) -> LineIndex
pub fn get_line_offset(&self, line: usize) -> Option<TextSize>
pub fn get_line(&self, offset: TextSize) -> Option<usize>
pub fn get_line_with_start_offset( &self, offset: TextSize, ) -> Option<(usize, TextSize)>
pub fn is_line_only_ascii(&self, line: TextSize) -> bool
pub fn line_count(&self) -> usize
pub fn get_col(&self, offset: TextSize, source_text: &str) -> Option<usize>
pub fn get_line_col( &self, offset: TextSize, source_text: &str, ) -> Option<(usize, usize)>
Sourcepub fn position_of(
&self,
offset: usize,
source_text: &str,
) -> Option<(usize, usize)>
pub fn position_of( &self, offset: usize, source_text: &str, ) -> Option<(usize, usize)>
The line and column of a byte offset given as a plain usize — the same answer as
LineIndex::get_line_col, for a caller that never sees a TextSize.
Every layer above this one spells an offset as a usize: crate::SourceRange is two of them, a parse
error is one (crate::CppParseError::offsets), and a language server’s positions are line and column
numbers rather than a rowan type. This is the single conversion point, which is why it exists instead of a
TextSize import wherever a diagnostic is turned into a protocol range.
An offset past the end of the text answers None. The alternative — the last line’s column, which is what
the line lookup alone would give — is a plausible position for an offset that is not in the file, and a
caller that got one would build a range pointing at code the offset never named. The end of the text is
itself a valid offset: it is where a zero-width range at EOF sits.
Sourcepub fn get_offset(
&self,
line: usize,
col: usize,
source_text: &str,
) -> Option<TextSize>
pub fn get_offset( &self, line: usize, col: usize, source_text: &str, ) -> Option<TextSize>
The offset of a line and column, both counted from zero.
The mapping a client’s positions come in through, and the one that has to be strict about where a line ends:
col is a column of that line, so a column past the line’s end is clamped to the line’s end (which is
what the protocol says to do with an over-long character value) — it is not allowed to walk into the next
line. The version this replaced clamped against the whole text instead, so get_offset(0, 99) on a
three-line file answered with an offset inside a later line: a position that is not in the file the caller
asked about, and one whose characters belong to a different line’s syntax.
None for a line the text does not have.
Trait Implementations§
Auto Trait Implementations§
impl Forget for LineIndex
impl Freeze for LineIndex
impl Move 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more