Skip to main content

SyntaxHighlighter

Struct SyntaxHighlighter 

Source
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

Source

pub fn new() -> Self

Source

pub fn with_language(lang: Language) -> Self

Source

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).

Source

pub fn set_language(&mut self, lang: Language)

Source

pub fn language(&self) -> Language

Source

pub fn incremental_edit_count(&self) -> u64

Number of incremental edits processed via Self::edit / Self::apply_input_edit_and_reparse.

Source

pub fn last_changed_lines(&self) -> &[Range<usize>]

Returns the line ranges invalidated during the most recent incremental reparse.

Source

pub fn tree(&self) -> Option<&Tree>

Accesses the active Tree-Sitter AST tree, if parsed.

Source

pub fn parse(&mut self, source: &str)

Parses a complete source text into a Tree-Sitter AST and initializes line lexer states.

Source

pub fn parse_buffer(&mut self, buffer: &LineBuffer)

Parses a LineBuffer directly via zero-copy rope slices (no full-document String copy).

Source

pub fn edit(&mut self, edit: &InputEdit)

Informs the Tree-Sitter AST and incremental line-state cache of an edit before re-parsing.

Source

pub fn parse_incremental(&mut self, source: &str)

Re-parses the document incrementally from a full &str using the edited previous AST.

Source

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.

Source

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.

Source

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.

Source

pub fn highlight_line(&self, line: &str, lang: Language) -> Vec<SyntaxToken>

Tokenizes a single line statelessly (backwards-compatible helper).

Source

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.

Source

pub fn tokenize_line_lexical(line: &str, lang: Language) -> Vec<SyntaxToken>

Stateless single-line tokenizer returning tokens with UTF-8 byte offsets.

Source

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).

Source

pub fn root_node(&self) -> Option<Node<'_>>

Returns the root node of the active Tree-Sitter syntax tree, if available.

Source

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.

Source

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.

Source

pub fn find_matching_bracket( &self, buffer: &LineBuffer, pos: Position, ) -> Option<Position>

Finds matching open or close bracket for delimiter at position pos.

Source

pub fn compute_fold_ranges(&self, buffer: &LineBuffer) -> Vec<FoldRange>

Extracts structural multi-line code folding regions for all 10 supported languages.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Clone for SyntaxHighlighter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SyntaxHighlighter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SyntaxHighlighter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoInitialState<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,