pub struct SyntaxHighlighter { /* private fields */ }Expand description
Syntax analysis engine providing real-time Tree-Sitter InputEdit incremental parsing,
10-language incremental line-state tokenization, structural code folding, and diagnostics.
Implementations§
Source§impl SyntaxHighlighter
impl SyntaxHighlighter
pub fn new() -> Self
pub fn with_language(lang: Language) -> Self
Sourcepub fn register_tree_sitter_language(&mut self, ts_lang: Language) -> bool
pub fn register_tree_sitter_language(&mut self, ts_lang: Language) -> bool
Registers an external tree_sitter::Language grammar on this highlighter instance
(e.g. if an application brings its own tree-sitter-python or tree-sitter-cpp crate).
pub fn set_language(&mut self, lang: Language)
pub fn language(&self) -> Language
Sourcepub fn incremental_edit_count(&self) -> u64
pub fn incremental_edit_count(&self) -> u64
Number of incremental edits processed via Self::edit / Self::apply_input_edit_and_reparse.
Sourcepub fn last_changed_lines(&self) -> &[Range<usize>]
pub fn last_changed_lines(&self) -> &[Range<usize>]
Returns the line ranges invalidated during the most recent incremental reparse.
Sourcepub fn parse(&mut self, source: &str)
pub fn parse(&mut self, source: &str)
Parses a complete source text into a Tree-Sitter AST and initializes line lexer states.
Sourcepub fn parse_buffer(&mut self, buffer: &LineBuffer)
pub fn parse_buffer(&mut self, buffer: &LineBuffer)
Parses a LineBuffer directly via zero-copy rope slices (no full-document String copy).
Sourcepub fn edit(&mut self, edit: &InputEdit)
pub fn edit(&mut self, edit: &InputEdit)
Informs the Tree-Sitter AST and incremental line-state cache of an edit before re-parsing.
Sourcepub fn parse_incremental(&mut self, source: &str)
pub fn parse_incremental(&mut self, source: &str)
Re-parses the document incrementally from a full &str using the edited previous AST.
Sourcepub fn reparse_incremental_buffer(
&mut self,
buffer: &LineBuffer,
dirty_start_row: usize,
dirty_end_row: usize,
) -> &[Range<usize>]
pub fn reparse_incremental_buffer( &mut self, buffer: &LineBuffer, dirty_start_row: usize, dirty_end_row: usize, ) -> &[Range<usize>]
Re-parses the LineBuffer incrementally via zero-copy rope slices after one or more
Self::edit calls, invalidating ONLY the lines whose AST or multi-line lexer state changed.
Sourcepub fn apply_input_edit_and_reparse(
&mut self,
edit: &InputEdit,
buffer: &LineBuffer,
) -> &[Range<usize>]
pub fn apply_input_edit_and_reparse( &mut self, edit: &InputEdit, buffer: &LineBuffer, ) -> &[Range<usize>]
Convenience single-edit incremental update: calls tree.edit(edit) and reparses via
zero-copy rope slices in a single call.
Sourcepub fn tokens_for_line_cached(
&mut self,
line_idx: usize,
buffer: &LineBuffer,
) -> &[SyntaxToken]
pub fn tokens_for_line_cached( &mut self, line_idx: usize, buffer: &LineBuffer, ) -> &[SyntaxToken]
Returns cached syntax tokens for line_idx, computing and memoizing them lazily on cache miss.
Sourcepub fn highlight_line(&self, line: &str, lang: Language) -> Vec<SyntaxToken>
pub fn highlight_line(&self, line: &str, lang: Language) -> Vec<SyntaxToken>
Tokenizes a single line statelessly (backwards-compatible helper).
Sourcepub fn highlight_line_ast(
&self,
line_idx: usize,
line: &str,
) -> Vec<SyntaxToken>
pub fn highlight_line_ast( &self, line_idx: usize, line: &str, ) -> Vec<SyntaxToken>
Extracts syntax tokens for a line using the active Tree-Sitter AST when present, falling back to the incremental multi-line state tokenizer for non-Tree-Sitter languages.
Sourcepub fn tokenize_line_lexical(line: &str, lang: Language) -> Vec<SyntaxToken>
pub fn tokenize_line_lexical(line: &str, lang: Language) -> Vec<SyntaxToken>
Stateless single-line tokenizer returning tokens with UTF-8 byte offsets.
Sourcepub fn scan_line_with_state(
line: &str,
lang: Language,
entry_state: &LineLexState,
) -> (Vec<SyntaxToken>, LineLexState)
pub fn scan_line_with_state( line: &str, lang: Language, entry_state: &LineLexState, ) -> (Vec<SyntaxToken>, LineLexState)
Core 10-language incremental line scanner returning (tokens_with_byte_offsets, exit_state).
Sourcepub fn root_node(&self) -> Option<Node<'_>>
pub fn root_node(&self) -> Option<Node<'_>>
Returns the root node of the active Tree-Sitter syntax tree, if available.
Sourcepub fn node_at_position(&self, line: usize, col: usize) -> Option<Node<'_>>
pub fn node_at_position(&self, line: usize, col: usize) -> Option<Node<'_>>
Finds the finest AST node at the given 0-indexed row and byte column.
Sourcepub fn enclosing_scope_range(
&self,
line: usize,
col: usize,
) -> Option<(usize, usize)>
pub fn enclosing_scope_range( &self, line: usize, col: usize, ) -> Option<(usize, usize)>
Finds the enclosing scope or block range (start_line, end_line) containing the given position.
Sourcepub fn find_matching_bracket(
&self,
buffer: &LineBuffer,
pos: Position,
) -> Option<Position>
pub fn find_matching_bracket( &self, buffer: &LineBuffer, pos: Position, ) -> Option<Position>
Finds matching open or close bracket for delimiter at position pos.
Sourcepub fn compute_fold_ranges(&self, buffer: &LineBuffer) -> Vec<FoldRange>
pub fn compute_fold_ranges(&self, buffer: &LineBuffer) -> Vec<FoldRange>
Extracts structural multi-line code folding regions for all 10 supported languages.
Sourcepub fn collect_syntax_diagnostics(
&self,
buffer: &LineBuffer,
) -> Vec<SyntaxDiagnostic>
pub fn collect_syntax_diagnostics( &self, buffer: &LineBuffer, ) -> Vec<SyntaxDiagnostic>
Collects real-time syntax diagnostics from the Tree-Sitter AST or structural validators (JSON, XML/SDF, TOML, unclosed brackets).
Sourcepub fn compute_auto_indent(&self, buffer: &LineBuffer, line_idx: usize) -> usize
pub fn compute_auto_indent(&self, buffer: &LineBuffer, line_idx: usize) -> usize
Computes indentation column spaces for a newly created newline following line line_idx.