Skip to main content

TreeSitterProcessor

Struct TreeSitterProcessor 

Source
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

Source

pub fn new(config: TreeSitterProcessorConfig) -> Result<Self, TreeSitterError>

Create a new processor from the given config.

Source

pub fn last_update_mode(&self) -> TreeSitterUpdateMode

Get the last update mode (useful for tests and instrumentation).

Source

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 char offsets), 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

Source

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:

Source

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_range can 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_range is 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.
Source

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 TextDelta describing the change from the previous version,
  • an optional full_text for (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:

Trait Implementations§

Source§

impl DocumentProcessor for TreeSitterProcessor

Source§

type Error = TreeSitterError

The error type returned by DocumentProcessor::process.
Source§

fn process( &mut self, state: &EditorStateManager, ) -> Result<Vec<ProcessingEdit>, Self::Error>

Compute derived state updates to apply to the editor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.