pub struct SyntaxHighlighter { /* private fields */ }Expand description
Syntax analysis engine providing real-time Tree-Sitter AST tokenization, incremental parsing, and structural navigation.
Implementations§
Source§impl SyntaxHighlighter
impl SyntaxHighlighter
pub fn new() -> Self
pub fn with_language(lang: Language) -> Self
pub fn set_language(&mut self, lang: Language)
pub fn language(&self) -> Language
Sourcepub fn edit(&mut self, edit: &InputEdit)
pub fn edit(&mut self, edit: &InputEdit)
Informs the Tree-Sitter AST of an edit for subsequent incremental parsing.
Sourcepub fn parse_incremental(&mut self, source: &str)
pub fn parse_incremental(&mut self, source: &str)
Re-parses the document incrementally using the edited previous AST.
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 for high-speed incremental viewport rendering.
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 directly from the active Tree-Sitter AST.
Sourcepub fn tokenize_line_lexical(line: &str, lang: Language) -> Vec<SyntaxToken>
pub fn tokenize_line_lexical(line: &str, lang: Language) -> Vec<SyntaxToken>
Fast lexical tokenizer fallback for languages without a Tree-Sitter grammar.
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 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>
Scans buffer or Tree-Sitter AST to locate multi-line code folding regions.
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.