pub struct PieceTree {
pub root: NodeRef,
pub transaction_depth: usize,
pub undo_stack: Vec<HistoryEntry>,
pub redo_stack: Vec<HistoryEntry>,
pub pieces: Pieces,
pub buffers: Buffers,
pub scratch_index_map: Vec<u32>,
/* private fields */
}Fields§
§root: NodeRef§transaction_depth: usizeTracks nested undo groups. 0 if we are outside any group.
undo_stack: Vec<HistoryEntry>§redo_stack: Vec<HistoryEntry>§pieces: Pieces§buffers: Buffers§scratch_index_map: Vec<u32>Implementations§
Source§impl PieceTree
impl PieceTree
Sourcepub fn take_snapshot(&self, current_cursor: u32) -> HistoryEntry
pub fn take_snapshot(&self, current_cursor: u32) -> HistoryEntry
Captures the current state of the document.
Sourcepub fn snap_to(&mut self, snapshot: HistoryEntry, current_cursor: u32) -> u32
pub fn snap_to(&mut self, snapshot: HistoryEntry, current_cursor: u32) -> u32
Restores the tree to a previously saved snapshot. Returns the cursor offset from the snapshot.
Source§impl PieceTree
impl PieceTree
Sourcepub fn begin_undo_group(&mut self, cursor_offset: u32)
pub fn begin_undo_group(&mut self, cursor_offset: u32)
Starts a new undo group, saves the current state if this is the outermost group.
Sourcepub fn end_undo_group(&mut self)
pub fn end_undo_group(&mut self)
Ends the current undo group
pub fn commit_head(&mut self, cursor_offset: u32)
pub fn try_undo(&mut self, current_cursor: u32) -> Option<u32>
pub fn try_redo(&mut self, current_cursor: u32) -> Option<u32>
pub fn total_length(&self) -> u32
pub fn apply_edits(&mut self, primary_cursor_offset: u32, edits: &mut [Edit])
Sourcepub fn insert_char(&mut self, offset: u32, ch: char)
pub fn insert_char(&mut self, offset: u32, ch: char)
Inserts a single character at the specified logical byte offset.
Sourcepub fn insert_char_no_commit(&mut self, offset: u32, ch: char)
pub fn insert_char_no_commit(&mut self, offset: u32, ch: char)
Inserts a single character at the specified logical byte offset.
pub fn insert(&mut self, offset: u32, text: &str)
pub fn remove_at(&mut self, offset: u32, length: u32)
pub fn insert_no_commit(&mut self, offset: u32, text: &str)
pub fn remove_no_commit(&mut self, offset: u32, length: u32)
pub fn get_piece(&self, index: NodeRef) -> Piece
pub fn find_position( &self, offset: u32, prefer_left: bool, ) -> Option<(NodeRef, u32)>
pub fn write_to<W: Write>(&self, writer: W) -> Result<()>
Source§impl PieceTree
impl PieceTree
Sourcepub fn node_arena_bytes(&self) -> u32
pub fn node_arena_bytes(&self) -> u32
Total bytes allocated for the node arena (includes NIL sentinel and all historical nodes retained for undo/redo).
Sourcepub fn mod_buffer_bytes(&self) -> u32
pub fn mod_buffer_bytes(&self) -> u32
Bytes consumed by the modifications buffer (append-only, never shrinks).
Sourcepub fn original_buffers_bytes(&self) -> u32
pub fn original_buffers_bytes(&self) -> u32
Bytes consumed by all original (read) buffers.
Sourcepub fn history_bytes(&self) -> u32
pub fn history_bytes(&self) -> u32
Bytes consumed by undo + redo history entries.
Sourcepub fn node_count(&self) -> u32
pub fn node_count(&self) -> u32
Number of live nodes in the arena (includes NIL and all historical nodes).
Sourcepub fn memory_usage(&self) -> MemoryUsage
pub fn memory_usage(&self) -> MemoryUsage
Aggregate memory usage breakdown.
Source§impl PieceTree
impl PieceTree
pub fn slice<R: RangeBounds<u32>>(&self, range: R) -> TreeSlice<'_>
Sourcepub fn slice_chars_range<R: RangeBounds<u32>>(&self, range: R) -> TreeSlice<'_>
pub fn slice_chars_range<R: RangeBounds<u32>>(&self, range: R) -> TreeSlice<'_>
Slice by char range.
Source§impl PieceTree
impl PieceTree
Sourcepub fn read_largest_contigous_chunk_at_byte(&self, offset: u32) -> &[u8] ⓘ
pub fn read_largest_contigous_chunk_at_byte(&self, offset: u32) -> &[u8] ⓘ
Fast-path chunk reader specifically designed for the Tree-sitter C API. Given an absolute byte offset, it returns the largest contiguous byte slice available starting exactly at that offset.
pub fn line_to_byte(&self, target_line: u32) -> Option<u32>
pub fn char_to_byte(&self, char_index: u32) -> Option<u32>
pub fn byte_to_char(&self, byte_offset: u32) -> Option<u32>
pub fn byte_to_line_col(&self, offset: u32) -> Option<(u32, u32)>
pub fn pieces(&self) -> PieceTreeIter<'_> ⓘ
pub fn get_line_range(&self, line: u32) -> Option<(u32, u32)>
pub fn get_line_content_allocating(&self, line: u32) -> Option<String>
Sourcepub fn chunks_at_byte(&self, start: u32, end: u32) -> ChunkIter<'_> ⓘ
pub fn chunks_at_byte(&self, start: u32, end: u32) -> ChunkIter<'_> ⓘ
Returns an iterator of &str chunks over the given byte range. Zero allocation.
Sourcepub fn char(&self, char_index: u32) -> Option<char>
pub fn char(&self, char_index: u32) -> Option<char>
Char at a given char index. O(log n) to find the piece, then a short scan within the piece.
Sourcepub fn slice_chars(&self, char_start: u32, char_end: u32) -> SliceChars<'_> ⓘ
pub fn slice_chars(&self, char_start: u32, char_end: u32) -> SliceChars<'_> ⓘ
Returns a non-allocating iterator of chars over the given char range.
Backed by TreeWalker::seek so it reuses existing infrastructure.
Sourcepub fn slice_bytes(&self, byte_start: u32, byte_end: u32) -> SliceChars<'_> ⓘ
pub fn slice_bytes(&self, byte_start: u32, byte_end: u32) -> SliceChars<'_> ⓘ
Returns a non-allocating iterator of chars over the given byte range.
Sourcepub fn line(&self, line: u32) -> Option<ChunkIter<'_>>
pub fn line(&self, line: u32) -> Option<ChunkIter<'_>>
Non-allocating line view: returns a ChunkIter over the byte range of
line. Line numbers are 0-based. The trailing \n is included if present.