pub struct SyntaxEdit {
pub start_byte: usize,
pub old_end_byte: usize,
pub new_end_byte: usize,
pub start_row: u32,
pub start_col: u32,
pub old_end_row: u32,
pub old_end_col: u32,
pub new_end_row: u32,
pub new_end_col: u32,
}Expand description
Edit information for incremental parsing.
Describes a text modification in terms that parsers can use for
efficient incremental re-parsing. Mirrors tree-sitter’s InputEdit
structure but without the tree-sitter dependency.
§Fields
The edit is described in terms of both byte offsets and row/column positions:
start_*: Where the edit beginsold_end_*: Where the old (replaced) content endednew_end_*: Where the new (inserted) content ends
§Example
use reovim_driver_syntax::SyntaxEdit;
// Inserting "Hello" at position 0
let edit = SyntaxEdit::insert(0, 0, 0, 5, 0, 5);
assert_eq!(edit.new_end_byte, 5);
assert_eq!(edit.old_end_byte, 0); // Nothing was replaced
// Deleting 10 bytes starting at position 5
let edit = SyntaxEdit::delete(5, 0, 5, 15, 0, 15);
assert_eq!(edit.start_byte, 5);
assert_eq!(edit.old_end_byte, 15);
assert_eq!(edit.new_end_byte, 5); // Nothing was insertedFields§
§start_byte: usizeByte offset where the edit starts.
old_end_byte: usizeByte offset where the old content ended.
new_end_byte: usizeByte offset where the new content ends.
start_row: u32Row (line) where the edit starts (0-indexed).
start_col: u32Column where the edit starts (0-indexed).
old_end_row: u32Row where old content ended.
old_end_col: u32Column where old content ended.
new_end_row: u32Row where new content ends.
new_end_col: u32Column where new content ends.
Implementations§
Source§impl SyntaxEdit
impl SyntaxEdit
Sourcepub const fn new(
start_byte: usize,
old_end_byte: usize,
new_end_byte: usize,
start_row: u32,
start_col: u32,
old_end_row: u32,
old_end_col: u32,
new_end_row: u32,
new_end_col: u32,
) -> Self
pub const fn new( start_byte: usize, old_end_byte: usize, new_end_byte: usize, start_row: u32, start_col: u32, old_end_row: u32, old_end_col: u32, new_end_row: u32, new_end_col: u32, ) -> Self
Create a new syntax edit with all fields specified.
Sourcepub const fn insert(
start_byte: usize,
start_row: u32,
start_col: u32,
new_end_byte: usize,
new_end_row: u32,
new_end_col: u32,
) -> Self
pub const fn insert( start_byte: usize, start_row: u32, start_col: u32, new_end_byte: usize, new_end_row: u32, new_end_col: u32, ) -> Self
Create an edit for an insertion (no content replaced).
When inserting, old_end equals start since nothing was removed.
Sourcepub const fn delete(
start_byte: usize,
start_row: u32,
start_col: u32,
old_end_byte: usize,
old_end_row: u32,
old_end_col: u32,
) -> Self
pub const fn delete( start_byte: usize, start_row: u32, start_col: u32, old_end_byte: usize, old_end_row: u32, old_end_col: u32, ) -> Self
Create an edit for a deletion (no content inserted).
When deleting, new_end equals start since nothing was inserted.
Sourcepub const fn affected_range(&self) -> Range<usize>
pub const fn affected_range(&self) -> Range<usize>
Get the byte range that was affected by this edit.
Returns the range from start to the maximum of old and new end.
Sourcepub const fn bytes_removed(&self) -> usize
pub const fn bytes_removed(&self) -> usize
Get the number of bytes that were removed.
Sourcepub const fn bytes_inserted(&self) -> usize
pub const fn bytes_inserted(&self) -> usize
Get the number of bytes that were inserted.
Sourcepub const fn byte_delta(&self) -> isize
pub const fn byte_delta(&self) -> isize
Get the net change in bytes (positive = growth, negative = shrink).
Sourcepub const fn is_replace(&self) -> bool
pub const fn is_replace(&self) -> bool
Check if this edit is a replacement (both removal and insertion).
Trait Implementations§
Source§impl Clone for SyntaxEdit
impl Clone for SyntaxEdit
Source§fn clone(&self) -> SyntaxEdit
fn clone(&self) -> SyntaxEdit
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more