pub struct BufferParser { /* private fields */ }Expand description
Per-buffer parser + last-parsed tree.
Implementations§
Source§impl BufferParser
impl BufferParser
Sourcepub fn new(
language: &str,
registry: &GrammarRegistry,
) -> Result<BufferParser, TsError>
pub fn new( language: &str, registry: &GrammarRegistry, ) -> Result<BufferParser, TsError>
pub fn language(&self) -> &str
Sourcepub fn reparse(&mut self, src: &str) -> Result<(), TsError>
pub fn reparse(&mut self, src: &str) -> Result<(), TsError>
Re-parse src from scratch. Passes None as the old tree on purpose:
tree-sitter’s incremental path requires the old tree to have been
Tree::edit-ed to reflect exactly what changed. Handing parse() an
un-edited old tree against changed source violates that contract and
can yield an incorrect tree — so the correct answer for an unknown delta
is a full parse. Callers that know the edit use
reparse_edit.
§Errors
Infallible today (tree-sitter returns None on failure, stored as-is);
the Result reserves fallibility for future timeout/cancel support.
Sourcepub fn reparse_edit(
&mut self,
old_src: &str,
new_src: &str,
start_byte: usize,
old_end_byte: usize,
) -> Result<(), TsError>
pub fn reparse_edit( &mut self, old_src: &str, new_src: &str, start_byte: usize, old_end_byte: usize, ) -> Result<(), TsError>
Incrementally re-parse after splicing [start_byte, old_end_byte) of
old_src to produce new_src. Edits the retained tree by the splice
(TsEdit) so tree-sitter reuses every unchanged subtree and reparses
only the affected span — O(edit), not O(document). With no prior tree
it falls back to a full parse. The result is identical to a full parse of
new_src (the differential-equivalence invariant, tested).
§Errors
Same as reparse.