pub struct TreeSitterProcessor { /* private fields */ }Expand description
An incremental Tree-sitter based document processor.
This processor tracks a parse tree and updates it based on TextDelta edits when available.
It then produces highlighting and folding edits in editor-core’s derived-state format.
Implementations§
Source§impl TreeSitterProcessor
impl TreeSitterProcessor
Sourcepub fn new(config: TreeSitterProcessorConfig) -> Result<Self, TreeSitterError>
pub fn new(config: TreeSitterProcessorConfig) -> Result<Self, TreeSitterError>
Create a new processor from the given config.
Sourcepub fn last_update_mode(&self) -> TreeSitterUpdateMode
pub fn last_update_mode(&self) -> TreeSitterUpdateMode
Get the last update mode (useful for tests and instrumentation).
Sourcepub fn expand_selection_syntax(
&self,
start: usize,
end: usize,
) -> Option<(usize, usize)>
pub fn expand_selection_syntax( &self, start: usize, end: usize, ) -> Option<(usize, usize)>
Expand a (start, end) selection to the next enclosing syntax node.
Returns None if the processor has no parsed tree yet (call process()/sync_to() first),
or if the selection is already at the root node.
Notes:
- Offsets are Unicode scalar indices (Rust
charoffsets), matching editor-core APIs. - The returned range is best-effort and is based on Tree-sitter node byte ranges mapped
through the processor’s internal
LineIndex.
Source§impl TreeSitterProcessor
impl TreeSitterProcessor
Sourcepub fn sync_to(
&mut self,
version: u64,
delta: Option<&TextDelta>,
full_text: Option<&str>,
) -> Result<TreeSitterUpdateMode, TreeSitterError>
pub fn sync_to( &mut self, version: u64, delta: Option<&TextDelta>, full_text: Option<&str>, ) -> Result<TreeSitterUpdateMode, TreeSitterError>
Synchronize the processor’s internal text/tree to the given version.
This updates the parse tree (incrementally when possible), but does not run any
Tree-sitter queries. Call Self::compute_processing_edits afterwards to produce
editor-core derived-state edits (highlighting + folding).
Notes:
- If
full_textisNoneand a full resync is required, this returnsTreeSitterError::DeltaMismatch.
Sourcepub fn compute_processing_edits(
&mut self,
char_range: Option<(usize, usize)>,
) -> Result<Vec<ProcessingEdit>, TreeSitterError>
pub fn compute_processing_edits( &mut self, char_range: Option<(usize, usize)>, ) -> Result<Vec<ProcessingEdit>, TreeSitterError>
Compute highlighting/folding edits from the current synchronized parse tree.
char_rangecan be used to limit Tree-sitter query execution to a subset of the document (useful as a performance degradation mode for huge files).
Notes:
- When
char_rangeis specified, the returned style intervals and fold regions will be partial (only within the range). Consumers that replace whole layers/regions should treat this as a “best effort visible range” optimization.
Sourcepub fn process_text(
&mut self,
version: u64,
delta: Option<&TextDelta>,
full_text: Option<&str>,
) -> Result<Vec<ProcessingEdit>, TreeSitterError>
pub fn process_text( &mut self, version: u64, delta: Option<&TextDelta>, full_text: Option<&str>, ) -> Result<Vec<ProcessingEdit>, TreeSitterError>
Process a document snapshot represented as:
- a monotonically increasing
version, - an optional
TextDeltadescribing the change from the previous version, - an optional
full_textfor (re-)synchronization.
This method is useful for running Tree-sitter processing on a background thread where
a full EditorStateManager is not available. Callers can pass full_text only when
performing an initial parse or when a delta mismatch requires a full re-sync.
Notes:
- If
full_textisNoneand a full sync is required, this returnsTreeSitterError::DeltaMismatch.
Trait Implementations§
Source§impl DocumentProcessor for TreeSitterProcessor
impl DocumentProcessor for TreeSitterProcessor
Source§type Error = TreeSitterError
type Error = TreeSitterError
DocumentProcessor::process.Source§fn process(
&mut self,
state: &EditorStateManager,
) -> Result<Vec<ProcessingEdit>, Self::Error>
fn process( &mut self, state: &EditorStateManager, ) -> Result<Vec<ProcessingEdit>, Self::Error>
Auto Trait Implementations§
impl !RefUnwindSafe for TreeSitterProcessor
impl !UnwindSafe for TreeSitterProcessor
impl Freeze for TreeSitterProcessor
impl Send for TreeSitterProcessor
impl Sync for TreeSitterProcessor
impl Unpin for TreeSitterProcessor
impl UnsafeUnpin for TreeSitterProcessor
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> 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