2021-11-07 05:31:12 +04:00
# Adding languages
2022-02-15 03:23:35 +04:00
## Language configuration
2021-11-07 05:31:12 +04:00
2022-06-21 03:15:50 +04:00
To add a new language, you need to add a `[[language]]` entry to the
`languages.toml` (see the [language configuration section]).
2022-02-15 03:23:35 +04:00
2022-04-10 21:50:05 +04:00
When adding a new language or Language Server configuration for an existing
language, run `cargo xtask docgen` to add the new configuration to the
[Language Support][lang-support] docs before creating a pull request.
2022-04-09 10:47:32 +04:00
When adding a Language Server configuration, be sure to update the
2022-04-10 21:50:05 +04:00
[Language Server Wiki][install-lsp-wiki] with installation notes.
2022-04-09 10:47:32 +04:00
2022-02-15 03:23:35 +04:00
## Grammar configuration
2022-06-21 03:15:50 +04:00
If a tree-sitter grammar is available for the language, add a new `[[grammar]]`
2022-02-15 03:23:35 +04:00
entry to `languages.toml` .
2022-06-21 03:15:50 +04:00
You may use the `source.path` key rather than `source.git` with an absolute path
to a locally available grammar for testing, but switch to `source.git` before
submitting a pull request.
2021-11-07 05:31:12 +04:00
## Queries
2021-12-21 06:03:44 +04:00
For a language to have syntax-highlighting and indentation among
other things, you have to add queries. Add a directory for your
language with the path `runtime/queries/<name>/` . The tree-sitter
[website ](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries )
gives more info on how to write queries.
> NOTE: When evaluating queries, the first matching query takes
precedence, which is different from other editors like neovim where
2022-02-15 03:23:35 +04:00
the last matching query supersedes the ones before it. See
2021-12-21 06:03:44 +04:00
[this issue][neovim-query-precedence] for an example.
2021-11-07 05:31:12 +04:00
## Common Issues
2022-03-08 10:13:15 +04:00
- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --grammar fetch` to fetch the grammars and `hx --grammar build` to build any out-of-date grammars.
2021-11-07 05:31:12 +04:00
2022-02-15 03:23:35 +04:00
- If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/<name>.so`
2021-11-07 05:31:12 +04:00
2022-06-21 03:15:50 +04:00
[language configuration section]: ../languages.md
2021-12-21 06:03:44 +04:00
[neovim-query-precedence]: https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090
2022-04-10 21:50:05 +04:00
[install-lsp-wiki]: https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers
[lang-support]: ../lang-support.md