pub struct CoordinateMapper<'a> { /* private fields */ }Expand description
Stateless mapper that converts freely between three coordinate systems:
- Byte offset — absolute position in the UTF-8 buffer.
- Line / Col (
LineCol) — 0-based line and byte-column. - 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>
impl<'a> CoordinateMapper<'a>
Sourcepub fn byte_to_line_col(&self, byte_offset: usize) -> Option<LineCol>
pub fn byte_to_line_col(&self, byte_offset: usize) -> Option<LineCol>
Byte offset -> LineCol.
Sourcepub fn line_col_to_byte(&self, lc: LineCol) -> Option<usize>
pub fn line_col_to_byte(&self, lc: LineCol) -> Option<usize>
LineCol -> byte offset.
Sourcepub fn byte_to_lsp(&self, byte_offset: usize) -> Option<LspPosition>
pub fn byte_to_lsp(&self, byte_offset: usize) -> Option<LspPosition>
Byte offset -> LspPosition.
Sourcepub fn lsp_to_byte(&self, pos: LspPosition) -> Option<usize>
pub fn lsp_to_byte(&self, pos: LspPosition) -> Option<usize>
LspPosition -> byte offset.
Sourcepub fn line_col_to_lsp(&self, lc: LineCol) -> Option<LspPosition>
pub fn line_col_to_lsp(&self, lc: LineCol) -> Option<LspPosition>
LineCol -> LspPosition.
Sourcepub fn lsp_to_line_col(&self, pos: LspPosition) -> Option<LineCol>
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> 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