pub trait SyntaxHighlighter:
Send
+ Sync
+ 'static {
// Required method
fn highlight_line(
&self,
buffer: &EditorBuffer,
row: usize,
line_text: &str,
) -> Vec<StyleSpan>;
// Provided methods
fn extract_links(
&self,
_buffer: &EditorBuffer,
_row: usize,
_line_text: &str,
) -> Vec<(Range<usize>, String)> { ... }
fn expand_line(
&self,
_buffer: &EditorBuffer,
_row: usize,
_concealed: &ConcealedLine,
) -> Vec<DisplayPad> { ... }
fn should_wrap_line(&self, _buffer: &EditorBuffer, _row: usize) -> bool { ... }
fn foldable_ranges(&self, _buffer: &EditorBuffer) -> Vec<FoldRange> { ... }
}Expand description
Trait implemented by language tokenizers and syntax highlighters.
Required Methods§
Sourcefn highlight_line(
&self,
buffer: &EditorBuffer,
row: usize,
line_text: &str,
) -> Vec<StyleSpan>
fn highlight_line( &self, buffer: &EditorBuffer, row: usize, line_text: &str, ) -> Vec<StyleSpan>
Analyzes a single line of text and returns all highlight spans for that line.
Ranges in the returned StyleSpans are byte offsets relative to line_text.
Provided Methods§
Sourcefn extract_links(
&self,
_buffer: &EditorBuffer,
_row: usize,
_line_text: &str,
) -> Vec<(Range<usize>, String)>
fn extract_links( &self, _buffer: &EditorBuffer, _row: usize, _line_text: &str, ) -> Vec<(Range<usize>, String)>
Optional extraction of hyperlinks on this line (source byte range -> URL).
The default implementation returns no links. Language plugins (e.g. Markdown) override this to expose clickable ranges without the canvas knowing the syntax.
Sourcefn expand_line(
&self,
_buffer: &EditorBuffer,
_row: usize,
_concealed: &ConcealedLine,
) -> Vec<DisplayPad>
fn expand_line( &self, _buffer: &EditorBuffer, _row: usize, _concealed: &ConcealedLine, ) -> Vec<DisplayPad>
Optional display-only padding for this line (e.g. table cell alignment).
Receives the collapsed ConcealedLine and returns insertions in
collapsed display coordinates (see DisplayPad). The default
implementation returns no padding.
Sourcefn should_wrap_line(&self, _buffer: &EditorBuffer, _row: usize) -> bool
fn should_wrap_line(&self, _buffer: &EditorBuffer, _row: usize) -> bool
Whether this line may soft-wrap when line_wrap is on.
Batteries return false for rows whose display alignment would break
across visual lines (e.g. Markdown table rows). The default is true.
Sourcefn foldable_ranges(&self, _buffer: &EditorBuffer) -> Vec<FoldRange>
fn foldable_ranges(&self, _buffer: &EditorBuffer) -> Vec<FoldRange>
Collapsible row ranges for this document (e.g. Markdown headings and
lists). Ranges must be sorted by start row with the header first.
The default is empty (nothing foldable); view state lives in
crate::folding::FoldState, not here.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".