Skip to main content

BlobHighlighter

Struct BlobHighlighter 

Source
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>

Source

pub fn new(grammar: &'text Grammar, text: &'text str) -> Self

Creates a blob highlighter and caches only the initial empty state.

Source

pub fn reset_text(&mut self, text: &'text str)

Replaces the blob text and clears cached line states.

Source

pub fn line_count(&self) -> usize

Returns the number of highlightable lines in the blob.

Source

pub fn line(&self, line: usize) -> Option<&'text str>

Returns a line by index, excluding line terminators.

Source

pub fn line_byte_range(&self, line: usize) -> Option<Range<usize>>

Returns a line’s byte range, excluding line terminators.

Source

pub fn is_state_cached(&self, line: usize) -> bool

Returns whether a start state for line is already cached.

Source

pub fn invalidate_from(&mut self, line: usize)

Invalidates cached states after a changed line.

Source

pub fn ensure_state(&mut self, line: usize) -> Option<&LineState>

Ensures the parser state at the start of line is cached.

Source

pub fn highlight_line_into( &mut self, line: usize, scopes: &mut Vec<ScopeSpan>, ) -> bool

Tokenizes one line into a caller-owned buffer.

Source

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.

Source

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.

Source

pub fn highlight_range_into( &mut self, range: Range<usize>, output: &mut Vec<OwnedLineTokens>, )

Tokenizes a line range into an owned output vector.

Source

pub fn highlighted_range(&mut self, range: Range<usize>) -> Vec<OwnedLineTokens>

Returns newly allocated token data for a line range.

Trait Implementations§

Source§

impl<'text> Debug for BlobHighlighter<'text>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'text> Freeze for BlobHighlighter<'text>

§

impl<'text> RefUnwindSafe for BlobHighlighter<'text>

§

impl<'text> Send for BlobHighlighter<'text>

§

impl<'text> Sync for BlobHighlighter<'text>

§

impl<'text> Unpin for BlobHighlighter<'text>

§

impl<'text> UnsafeUnpin for BlobHighlighter<'text>

§

impl<'text> UnwindSafe for BlobHighlighter<'text>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.