Adding new languages to Helix
In order to add a new language to Helix, you will need to follow the steps below.
Language configuration
- Add a new
[[language]]entry in thelanguages.tomlfile and provide the necessary configuration for the new language. For more information on language configuration, refer to the language configuration section of the documentation. A new language server can be added by extending the[language-server]table in the same file. - If you are adding a new language or updating an existing language server
configuration, run the command
cargo xtask docgento update the Language Support documentation.
💡 If you are adding a new Language Server configuration, make sure to update the Language Server Wiki with the installation instructions.
Grammar configuration
- If a tree-sitter grammar is available for the new language, add a new
[[grammar]]entry to thelanguages.tomlfile. - If you are testing the grammar locally, you can use the
source.pathkey with an absolute path to the grammar. However, before submitting a pull request, make sure to switch to usingsource.git.
Queries
-
In order to provide syntax highlighting and indentation for the new language, you will need to add queries.
-
Create a new directory for the language with the path
runtime/queries/<name>/. -
Refer to the tree-sitter website for more information on writing queries.
-
The highlight captures (
@function,@type, …) and how they resolve are documented on the themes page: match the most specific scope that fits, capture the leaf node you mean, and remember that the last matching pattern (and the innermost node) wins. -
Helix loads several query files from that directory; only
highlights.scmis required:File Purpose Guide highlights.scmsyntax highlighting highlights.md injections.scmembed other languages in regions (strings, code fences) injection.md indents.scmindentation indent.md textobjects.scmtextobjects and navigation ( mif,]f, …)textobject.md locals.scmscope tracking so locals highlight distinctly locals.md tags.scmdocument/workspace symbol pickers tags.md rainbows.scmrainbow brackets rainbow_bracket_queries.md A query file may reuse another language’s with
; inherits: <lang>on the first line. Runcargo xtask query-check [language]to check that the queries are valid against the grammar.
Common issues
- If you encounter errors when running Helix after switching branches, you may
need to update the tree-sitter grammars. Run the command
hx --grammar fetchto fetch the grammars andhx --grammar buildto build any out-of-date grammars. - If a parser is causing a segfault, or you want to remove it, make sure to
remove the compiled parser located at
runtime/grammars/<name>.so. - If you are attempting to add queries and Helix is unable to locate them, ensure that the environment variable
HELIX_RUNTIMEis set to the location of theruntimefolder you’re developing in. - Validate queries with
cargo xtask query-check [language](every query file must compile against the grammar).highlight-checkandindent-checkadditionally run the real highlighter and indenter over the test fixtures catch mistakes.