pub trait DocumentRangeSemanticTokensProvider {
// Required methods
fn legend(&self) -> SemanticTokensLegend;
fn semantic_tokens(
&self,
text: &Rope,
range: Range<usize>,
window: &mut Window,
cx: &mut App,
) -> Task<Result<SemanticTokens>> ⓘ;
}Expand description
A provider of semantic highlighting tokens, layered on top of the
built-in tree-sitter SyntaxHighlighter.
This is the editor counterpart of the LSP
textDocument/semanticTokens/range request (and Monaco Editor’s
DocumentRangeSemanticTokensProvider). Like the other
providers on Lsp — DocumentColorProvider,
HoverProvider, … — it is installed on InputBaseState::lsp, fetched
asynchronously when the document changes, and its result is cached and
composed into the render pipeline. It does not replace the
tree-sitter highlighter.
§Token names and theming
Returned tokens are delta-encoded with a numeric token_type that
indexes legend.token_types. The editor resolves each
type name against the active
HighlightTheme at paint time —
the same vocabulary the tree-sitter path uses ("keyword", "comment",
"string", …; "keyword.modifier" falls back to "keyword"). Because
the color is resolved from the name on every paint, theme switches
recolor semantic tokens with no provider cooperation. Token modifiers
are accepted but not currently mapped to styles.
Required Methods§
Sourcefn legend(&self) -> SemanticTokensLegend
fn legend(&self) -> SemanticTokensLegend
The legend naming the numeric token_type field of the tokens
returned by semantic_tokens. Each entry in
SemanticTokensLegend::token_types is resolved against the active
HighlightTheme.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".