pub struct BlobHighlighter<'text> { /* private fields */ }Expand description
Incremental highlighter for a complete text blob.
The highlighter caches parser states and per-line scope spans so callers can
ask for individual lines or ranges without reparsing the whole blob each
time. Editing callers should call BlobHighlighter::reset_text or
BlobHighlighter::invalidate_from to keep those caches aligned with the
backing text.
Implementations§
Source§impl<'text> BlobHighlighter<'text>
impl<'text> BlobHighlighter<'text>
Sourcepub fn new(grammar: &'text Grammar, text: &'text str) -> Self
pub fn new(grammar: &'text Grammar, text: &'text str) -> Self
Creates a blob highlighter and caches only the initial empty state.
Sourcepub fn reset_text(&mut self, text: &'text str)
pub fn reset_text(&mut self, text: &'text str)
Replaces the blob text and clears cached line states.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Returns the number of highlightable lines in the blob.
Sourcepub fn line(&self, line: usize) -> Option<&'text str>
pub fn line(&self, line: usize) -> Option<&'text str>
Returns a line by index, excluding line terminators.
Sourcepub fn line_byte_range(&self, line: usize) -> Option<Range<usize>>
pub fn line_byte_range(&self, line: usize) -> Option<Range<usize>>
Returns a line’s byte range, excluding line terminators.
Sourcepub fn is_state_cached(&self, line: usize) -> bool
pub fn is_state_cached(&self, line: usize) -> bool
Returns whether a start state for line is already cached.
Sourcepub fn invalidate_from(&mut self, line: usize)
pub fn invalidate_from(&mut self, line: usize)
Invalidates cached states after a changed line.
Sourcepub fn ensure_state(&mut self, line: usize) -> Option<&LineState>
pub fn ensure_state(&mut self, line: usize) -> Option<&LineState>
Ensures the parser state at the start of line is cached.
Sourcepub fn highlight_line_into(
&mut self,
line: usize,
scopes: &mut Vec<ScopeSpan>,
) -> bool
pub fn highlight_line_into( &mut self, line: usize, scopes: &mut Vec<ScopeSpan>, ) -> bool
Tokenizes one line into a caller-owned buffer.
Sourcepub fn highlight_range<F>(&mut self, range: Range<usize>, f: F)where
F: FnMut(LineTokens<'_, '_>),
pub fn highlight_range<F>(&mut self, range: Range<usize>, f: F)where
F: FnMut(LineTokens<'_, '_>),
Tokenizes a line range and invokes f for each requested line.
Sourcepub fn highlight_styled_range<F>(
&mut self,
theme: &Theme,
range: Range<usize>,
f: F,
)where
F: FnMut(StyledLine<'_, '_>),
pub fn highlight_styled_range<F>(
&mut self,
theme: &Theme,
range: Range<usize>,
f: F,
)where
F: FnMut(StyledLine<'_, '_>),
Tokenizes and styles a line range and invokes f for each requested line.
Sourcepub fn highlight_range_into(
&mut self,
range: Range<usize>,
output: &mut Vec<OwnedLineTokens>,
)
pub fn highlight_range_into( &mut self, range: Range<usize>, output: &mut Vec<OwnedLineTokens>, )
Tokenizes a line range into an owned output vector.
Sourcepub fn highlighted_range(&mut self, range: Range<usize>) -> Vec<OwnedLineTokens>
pub fn highlighted_range(&mut self, range: Range<usize>) -> Vec<OwnedLineTokens>
Returns newly allocated token data for a line range.