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
impl RealtimeParser
Sourcepub fn new(source: impl Into<String>) -> Result<Self, ParseError>
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.
Sourcepub fn apply_edit(&mut self, edit: &TextEdit) -> Result<(), ParseError>
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.
Sourcepub fn syntax(&self) -> &SourceFile
pub fn syntax(&self) -> &SourceFile
Returns the typed syntax for the current snapshot.
Sourcepub fn diagnostics(&self) -> &[LexError]
pub fn diagnostics(&self) -> &[LexError]
Returns the recoverable diagnostics for the current snapshot.
Sourcepub fn changed_ranges(&self) -> &[Span]
pub fn changed_ranges(&self) -> &[Span]
Returns structural ranges changed by the most recent incremental parse.
Sourcepub fn into_syntax(self) -> SourceFile
pub fn into_syntax(self) -> SourceFile
Consumes the retained parser and returns its current typed syntax.