Skip to main content

LineIndex

Struct LineIndex 

Source
pub struct LineIndex { /* private fields */ }

Implementations§

Source§

impl LineIndex

Source

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.

Source

pub fn parse(text: &str) -> LineIndex

Source

pub fn get_line_offset(&self, line: usize) -> Option<TextSize>

Source

pub fn get_line(&self, offset: TextSize) -> Option<usize>

Source

pub fn get_line_with_start_offset( &self, offset: TextSize, ) -> Option<(usize, TextSize)>

Source

pub fn is_line_only_ascii(&self, line: TextSize) -> bool

Source

pub fn line_count(&self) -> usize

Source

pub fn get_col(&self, offset: TextSize, source_text: &str) -> Option<usize>

Source

pub fn get_line_col( &self, offset: TextSize, source_text: &str, ) -> Option<(usize, usize)>

Source

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.

Source

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§

Source§

impl Clone for LineIndex

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LineIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.