pub struct LineIndex<'a> { /* private fields */ }Implementations§
Source§impl<'a> LineIndex<'a>
impl<'a> LineIndex<'a>
pub fn new(content: &'a str) -> Self
pub fn line_col_to_byte_range(&self, line: usize, column: usize) -> Range<usize>
Sourcepub fn line_col_to_byte_range_with_length(
&self,
line: usize,
column: usize,
length: usize,
) -> Range<usize>
pub fn line_col_to_byte_range_with_length( &self, line: usize, column: usize, length: usize, ) -> Range<usize>
Calculate a proper byte range for replacing text with a specific length This is the correct function to use for LSP fixes
§Safety
This function correctly handles multi-byte UTF-8 characters by converting character positions (columns) to byte positions.
Sourcepub fn whole_line_range(&self, line: usize) -> Range<usize>
pub fn whole_line_range(&self, line: usize) -> Range<usize>
Calculate byte range for entire line replacement (including newline) This is ideal for rules that need to replace complete lines
Sourcepub fn multi_line_range(
&self,
start_line: usize,
end_line: usize,
) -> Range<usize>
pub fn multi_line_range( &self, start_line: usize, end_line: usize, ) -> Range<usize>
Calculate byte range spanning multiple lines (from start_line to end_line inclusive) Both lines are 1-indexed. This is useful for replacing entire blocks like tables.
Sourcepub fn line_text_range(
&self,
line: usize,
start_col: usize,
end_col: usize,
) -> Range<usize>
pub fn line_text_range( &self, line: usize, start_col: usize, end_col: usize, ) -> Range<usize>
Calculate byte range for text within a line (excluding newline) Useful for replacing specific parts of a line
§Safety
This function correctly handles multi-byte UTF-8 characters by converting character positions (columns) to byte positions.
Sourcepub fn line_content_range(&self, line: usize) -> Range<usize>
pub fn line_content_range(&self, line: usize) -> Range<usize>
Calculate byte range from start of line to end of line content (excluding newline) Useful for replacing line content while preserving line structure
Sourcepub fn get_line_start_byte(&self, line_num: usize) -> Option<usize>
pub fn get_line_start_byte(&self, line_num: usize) -> Option<usize>
Get the global start byte offset for a given 1-based line number.
Sourcepub fn is_code_block(&self, line: usize) -> bool
pub fn is_code_block(&self, line: usize) -> bool
Check if the line at the given index is within a code block
Sourcepub fn is_code_fence(&self, line: usize) -> bool
pub fn is_code_fence(&self, line: usize) -> bool
Check if the line is a code fence marker (``` or ~~~)
Sourcepub fn is_tilde_code_block(&self, line: usize) -> bool
pub fn is_tilde_code_block(&self, line: usize) -> bool
Check if the line is a tilde code fence marker (~~~)
Sourcepub fn get_content(&self) -> &str
pub fn get_content(&self) -> &str
Get a reference to the content
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for LineIndex<'a>
impl<'a> RefUnwindSafe for LineIndex<'a>
impl<'a> Send for LineIndex<'a>
impl<'a> Sync for LineIndex<'a>
impl<'a> Unpin for LineIndex<'a>
impl<'a> UnwindSafe for LineIndex<'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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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