Tree-sitter Highlight
Usage
Add this crate, and the language-specific crates for whichever languages you want
to parse, to your Cargo.toml
:
[]
= "0.22.0"
= "0.21.3"
Define the list of highlight names that you will recognize:
let highlight_names = ;
Create a highlighter. You need one of these for each thread that you're using for syntax highlighting:
use Highlighter;
let mut highlighter = new;
Load some highlighting queries from the queries
directory of the language repository:
use HighlightConfiguration;
let javascript_language = language;
let mut javascript_config = new.unwrap;
Configure the recognized names:
javascript_config.configure;
Highlight some code:
use HighlightEvent;
let highlights = highlighter.highlight.unwrap;
for event in highlights
The last parameter to highlight
is a language injection callback. This allows
other languages to be retrieved when Tree-sitter detects an embedded document
(for example, a piece of JavaScript code inside a script
tag within HTML).