foxundermoon / vscode-tree-sitter

Accurate syntax coloring for VSCode using tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tree Sitter for VSCode

This extension gives VSCode support for tree-sitter syntax coloring. Examples with tree-sitter coloring on the right:

Go

Go

Rust

Rust

C++

C++

Ruby

Ruby

Typescript

Typescript

Contributing

Fixing colorization of an existing language

If you see something getting colored wrong, or something that should be colored but isn't, please make a PR to fix it! Colorization is performed by the various colorLanguage(x, editor) functions at the top of extension.ts. When working on the colorization rules, please keep in mind two core principles:

  1. Good colorization is consistent. It's better to not color at all than to color inconsistently.
  2. Good colorization is selective. The fewer things that we color, the more emphasis the color gives.

Adding a new language

It's straightforward to add any language with a tree-sitter grammar.

  1. Add a dependency on the npm package for that language: npm install tree-sitter-yourlang.
  2. Add the language and color function to the dictionary in ./lib/extension.ts.
  3. Add a simplified TextMate grammar to ./src/yourlang.tmLanguage.json. The job of this textmate grammar is just to color keywords and literals.
  4. Add a reference to the grammar to the contributes.grammars section of package.json. yourlang must be a VSCode language identifier.
  5. Add a reference to onLanguage:yourlang to the activationEvents section of package.json. yourlang must be a VSCode language identifier.
  6. Add an example to examples/yourlang.
  7. Hit F5 in VSCode, with this project open, to test your changes.
  8. Take a screenshot comparing before-and-after and add it to the above list.
  9. Submit a PR!

About

Accurate syntax coloring for VSCode using tree-sitter

License:MIT License


Languages

Language:TypeScript 96.4%Language:Shell 3.6%