Skip to main content

InputHighlighter

Trait InputHighlighter 

Source
pub trait InputHighlighter {
    // Required methods
    fn language(&self) -> SharedString;
    fn update(
        &mut self,
        edit: Option<InputEdit>,
        text: &Rope,
        folding: bool,
        window: &mut Window,
        cx: &mut Context<'_, EditorState>,
    );
    fn styles(
        &self,
        range: &Range<usize>,
        resolver: &dyn HighlightStyleResolver,
    ) -> Vec<(Range<usize>, HighlightStyle)>;
    fn fold_ranges(&self, text: &Rope) -> Vec<FoldRange>;

    // Provided methods
    fn update_batch(
        &mut self,
        edits: &[(InputEdit, Rope)],
        folding: bool,
        window: &mut Window,
        cx: &mut Context<'_, EditorState>,
    ) { ... }
    fn fold_ranges_for_edit(
        &self,
        range: Range<usize>,
        text: &Rope,
    ) -> Vec<FoldRange> { ... }
}
Expand description

Parser-independent syntax highlighting seam consumed by the Base editor.

Implementations own parsing, incremental state, and language-specific behavior. Base only asks for styled ranges and fold candidates.

Required Methods§

Source

fn language(&self) -> SharedString

Source

fn update( &mut self, edit: Option<InputEdit>, text: &Rope, folding: bool, window: &mut Window, cx: &mut Context<'_, EditorState>, )

Source

fn styles( &self, range: &Range<usize>, resolver: &dyn HighlightStyleResolver, ) -> Vec<(Range<usize>, HighlightStyle)>

Return ordered, non-overlapping style runs that fully cover range. Use HighlightStyle::default for text without a semantic style.

Source

fn fold_ranges(&self, text: &Rope) -> Vec<FoldRange>

Provided Methods§

Source

fn update_batch( &mut self, edits: &[(InputEdit, Rope)], folding: bool, window: &mut Window, cx: &mut Context<'_, EditorState>, )

Apply several edits made as one change, such as typing with multiple cursors. Each entry is an edit with the text as it stood right after it, in the order the edits were applied.

The default hands each edit to Self::update in turn. Override it to reparse once for the whole change.

Source

fn fold_ranges_for_edit( &self, range: Range<usize>, text: &Rope, ) -> Vec<FoldRange>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§