sublime-treesitter / TreeSitter

Sublime Text Tree-sitter configuration and abstraction layer
MIT License
19 stars 1 forks source link

question: how to install new grammar? #16

Closed bokunodev closed 3 months ago

bokunodev commented 4 months ago

how to add new grammar that isn't listed in the menu? where should i put grammar.js and the parser files?

kylebebak commented 3 months ago

Some of the info you're looking for is here in the README: https://github.com/sublime-treesitter/TreeSitter?tab=readme-ov-file#manage-your-own-language-repos-and-binaries

To manage your own languages, you need to do a few things in the STS settings. Search for Preferences: TreeSitter Settings in the command palette

Here's an example of how to do this for e.g. dart

Your settings would look something like this. Then you could run TreeSitter: Install Language and install dart. STS would download the language repo, build the language binary, instantiate the language, and use it to parse code in any buffer with a scope of source.dart

{
  "python_path": "~/.pyenv/versions/3.8.13/bin/python",
  "installed_languages": [
    "python",
    "json",
  ],
  "language_name_to_repo": {
    "dart": {"repo": "UserNobody14/tree-sitter-dart"},
  },
  "language_name_to_scopes": {
    "dart": [
      "source.dart",
    ],
  },
}