Skip to main content

RealtimeParser

Struct RealtimeParser 

Source
pub struct RealtimeParser { /* private fields */ }
Expand description

An incrementally updated Tree-sitter parse for editor-style source changes.

The parser retains its previous Tree-sitter tree, applies each TextEdit to that tree, and supplies it to the next parse. Typed syntax is lowered afresh from the incrementally produced tree, so every public node and span describes the current source snapshot. Missing group closers are recoverable and remain available through Self::diagnostics.

Implementations§

Source§

impl RealtimeParser

Source

pub fn new(source: impl Into<String>) -> Result<Self, ParseError>

Creates a retained parse of the initial source snapshot.

§Errors

Returns ParseError when the grammar cannot parse and lower the source, apart from recoverable missing group and string-literal closers.

Source

pub fn apply_edit(&mut self, edit: &TextEdit) -> Result<(), ParseError>

Applies one source edit and incrementally refreshes the typed syntax.

The update is transactional: a failed edit or parse leaves the previous source, tree, syntax, and diagnostics unchanged.

§Errors

Returns ParseError::InvalidEdit when the edit is outside the current UTF-8 buffer, or another ParseError when the edited source cannot be recovered and lowered.

Source

pub fn source(&self) -> &str

Returns the current source snapshot.

Source

pub fn syntax(&self) -> &SourceFile

Returns the typed syntax for the current snapshot.

Source

pub fn diagnostics(&self) -> &[LexError]

Returns the recoverable diagnostics for the current snapshot.

Source

pub fn changed_ranges(&self) -> &[Span]

Returns structural ranges changed by the most recent incremental parse.

Source

pub fn into_syntax(self) -> SourceFile

Consumes the retained parser and returns its current typed syntax.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.