Helix
Contents
Overview
Helix is a modal, character-based text editor.
Helix does not natively provide an editing environment for ConTeXt, but does provide excellent support for Tree-Sitter parsers and Language Server Protocol servers, which can provide a good deal of support for editing ConTeXt source files.
Tree-Sitter Support
Helix can be configured to use the ConTeXt Tree-Sitter parser.
Helix provides documentation for adding a tree-sitter grammar here: https://docs.helix-editor.com/guides/adding_languages.html
Language Server Protocol Support
Helix can support Language Server Protocol servers.
Example Configuration
This minimal example configuration enables:
- Syntax highlighting for ConTeXt markup
- Injections for Lua code code environments, and various typing environments
Configuring languages.toml
In the Helix configuration directory (usually ~/.config/helix
), create or edit the file languages.toml
to include the following:
[[language]] name = "context" scope = "source.context" file-types = ["lmtx", "ctx"] [[grammar]] name = "context" [source] git = "https://github.com/pmazaitis/tree-sitter-context" rev = "4522ee13d58373f79d163df2baef80ea66908a8e"
Notes:
- In testing, including
"tex"
in the filetypes list will disable ConTeXt highlighting (a conflict with LaTeX support?). - The
rev
field points to a specific git commit in the referenced GitHub repository. This reference will need to be updated manually (to either a long hash or a tag) to take advantage of newer versions of the tree-sitter parser.
More configuration options are detailed in the Helix languages.toml documentation.
Adding Queries
For Helix to make use of Tree-Sitter, we must also supply query files to teach Helix what to do with the parser output.
Query files are stored in a subfolder of the Helix configuration directory (usually ~/.config/helix/runtime/queries/context
, for queries relating to the context
langauge).
A sample query file for syntax highlighting:
; ~/.config/helix/runtime/queries/context/highlights.scm ; ; highlights.scm for tree-sitter-context (text) @user.text (title_setting (value (value_brace_group (value_brace_group_text) @user.text))) (command_name) @command.name (settings_block) @command.set (option_block) @command.set (line_comment) @comment (escaped) @escaped (inline_math) @math
A sample query file for handling injections:
; ~/.config/helix/runtime/queries/context/injections.scm ; ; injections.scm for tree-sitter-context ((code_lua_body) @injection.content (#set! injection.language "lua")) ((typing_html_body) @injection.content (#set! injection.language "html")) ((typing_css_body) @injection.content (#set! injection.language "css")) ((typing_lua_body) @injection.content (#set! injection.language "lua")) ((typing_xml_body) @injection.content (#set! injection.language "xml")) ((typing_parsedxml_body) @injection.content (#set! injection.language "xml"))