Skip to main content

CoordinateMapper

Struct CoordinateMapper 

Source
pub struct CoordinateMapper<'a> { /* private fields */ }
Expand description

Stateless mapper that converts freely between three coordinate systems:

  1. Byte offset — absolute position in the UTF-8 buffer.
  2. Line / Col (LineCol) — 0-based line and byte-column.
  3. LSP position (LspPosition) — 0-based line and UTF-16 column.

All conversions go through a LineIndex that must be kept in sync with the buffer text (rebuild after each edit batch).

Implementations§

Source§

impl<'a> CoordinateMapper<'a>

Source

pub fn new(index: &'a LineIndex) -> Self

Create a mapper backed by the given line index.

Source

pub fn byte_to_line_col(&self, byte_offset: usize) -> Option<LineCol>

Byte offset -> LineCol.

Source

pub fn line_col_to_byte(&self, lc: LineCol) -> Option<usize>

LineCol -> byte offset.

Source

pub fn byte_to_lsp(&self, byte_offset: usize) -> Option<LspPosition>

Byte offset -> LspPosition.

Source

pub fn lsp_to_byte(&self, pos: LspPosition) -> Option<usize>

LspPosition -> byte offset.

Source

pub fn line_col_to_lsp(&self, lc: LineCol) -> Option<LspPosition>

LineCol -> LspPosition.

Source

pub fn lsp_to_line_col(&self, pos: LspPosition) -> Option<LineCol>

LspPosition -> LineCol.

Auto Trait Implementations§

§

impl<'a> Freeze for CoordinateMapper<'a>

§

impl<'a> RefUnwindSafe for CoordinateMapper<'a>

§

impl<'a> Send for CoordinateMapper<'a>

§

impl<'a> Sync for CoordinateMapper<'a>

§

impl<'a> Unpin for CoordinateMapper<'a>

§

impl<'a> UnsafeUnpin for CoordinateMapper<'a>

§

impl<'a> UnwindSafe for CoordinateMapper<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.