tree-sitter-vscodeBring the power of Tree-sitter to VSCode! DescriptionThis extension adds syntactic and semantic highlighting with Tree-sitter to Visual Studio Code. By default, VSCode uses TextMate grammars for fast syntax highlighting and Language Servers for the more sophisticated semantic highlighting. TextMate grammars, however, are RegEx based and can therefore not fully represent most programming languages. A fully-fledged language server, on the other hand, is a lot of work, and therefore might be too much effort for toy projects or DSLs. The middle-ground is, were Tree-sitter shines. It supports more powerful grammars, while still being easy to write. And it comes with the benefit, that injecting other languages is a breeze! What this extension does, is register a "semantic token provider" with VSCode, that executes a user-supplied Tree-sitter parser on the given file. The parsed tree is then queried for tokens which should be highlighted. The collected tokens are then given to VSCode with their highlighting information. Have a look at the Tree-sitter homepage to learn how to write a Tree-sitter grammar or skim through the list of the many available parsers ready to use. ConfigurationThis extension does not come with any built-in parsers.
To use your own parser, you need to specify its location
and the location of the query files on the file system in the
Note, that this extension uses the WASM bindings for the Tree-sitter parsers. Have a look here to see how you can generate those.
Changing the activation eventI am no clairvoyant (unfortunately)
and therefore don't know which languages you want to use this extension with.
This is why, by default, this extension will be activated on any language
(though parsing will only be performed on configured languages).
If you want to change that behavior, you need to modify this extension's
Injecting other languagesQueries inside the injections file will be parsed and highlighted by the parser with the same name as the query. So, to highlight something as Python code, the following query is sufficient:
However, the standard way of injecting other languages with Tree-sitter is not yet supported. Adding custom languages to VSCodeUnfortunately, I haven't been able to figure out a way to add custom languages to VSCode natively. As far as I know, this is only possible through plugins, which need to specify the language details. If you don't want to write your own plugin, however,
you can use the following hack.
Just go to the extensions folder of VSCode (Command Extensions: Open Extension Folder)
and modify an existing extensions'
|