Language Support
Helix implements the Language Server Protocol ↗ (LSP) which allows support for loved language-specific features such as:
- Intellisense
- Goto Definition
- View documentation on hover
- Workspace symbol search
- Diagnostics
What is an “LSP”?
Historically, each individual editor had to implement a set of tools for each individual language.
This was chaotic and meant that there was an extremely high cost to developing a text editor with features such as goto definition, intellisense, documentation on hover and diagnostics.
Thankfully, with the introduction of the LSP everything changed — as it standardized a means of communications between editors and languages.
Nowadays, instead of editors having to implement support for every language in existence, they just need to implement one feature — the LSP.
Third parties will each create a language server, which provides functionalities for a specific language.
The implementor of the LSP communicates with all of those language servers to provide desired editor functionality.
As a bonus, this significantly reduced the barrier of entry to have great editor tooling per-language. Do you use some obscure language that no one has heard about since the 90s at your work? Consider implementing a language server ↗ for it to make your life easier.
Default configurations for languages are available for many many languages, and you can also add your own.
In this guide we’ll explore how to setup language server for Go, as well as formatting on save. The process will be similar for other languages.
First, let’s check what we need to add Go support. Use hx --health <language>
to check the status of go
. For example:
hx --health go
Since we’ve just recently installed Helix, we haven’t set anything up yet.
Configured language servers: ✘ gopls: 'gopls' not found in $PATH ✘ jedi-language-server: 'golangci-lint-langserver' not found in $PATHConfigured debug adapter: dlvBinary for debug adapter: 'dlv' not found in $PATHConfigured formatter: NoneHighlight queries: ✓Textobject queries: ✓Indent queries: ✓
Despite the fact, syntax highlighting is available out of the box with zero configuration. Neat!
Language Server
Helix tells us that gopls
is already configured, even though we haven’t installed it. Install it using your operating system’s package manager!
After installing it, let’s check hx --health
yet again:
Configured language servers: ✓ gopls: /path/to/gopls ✘ jedi-language-server: 'golangci-lint-langserver' not found in $PATHConfigured debug adapter: dlvBinary for debug adapter: 'dlv' not found in $PATHConfigured formatter: NoneHighlight queries: ✓Textobject queries: ✓Indent queries: ✓
Helix is able to recognize the path of the gopls
we’ve installed. At this point language features like intellisense will just work, as Helix configures them by default.
Formatter
Language support is useful, but over the years most people have stopped manually formatting code and let that job be automated by tools called formatters.
Formatters take your file as input, and adjust insignificant whitespace to conform it to certain standards. Examples of formatters include biome ↗ and rustfmt ↗.
Let’s configure a formatter for Go which will perform its job every time we save the file. One of the popular formatters for Go is called gofumpt
↗, so we’ll go with it.
Install gofumpt
with your operating system’s package manager, similar to how you’ve installed the language server (gopls
) previously.
To configure gopls
to format on save, create a languages.toml
file in your helix config directory, which will vary by operating system:
- Linux and Mac:
~/.config/helix/languages.toml
- Windows:
%AppData%\helix\languages.toml
Add the following language entry to the file:
[language-server.gopls.config]gofumpt = true
Every time you save your Go files, they will be automatically formatted. For times when this is undesired, see saving a file without formatting.
Now go into your Go file and check, formatting and LSP will both work!
Useful keymaps
To invoke language server functionalities, use the following keymap
Helix includes default keymap for using language server functionality. Some examples:
- Space + r renames the symbol under the cursor across the project
- Space + k will show documentation for the symbol under the cursor
- g + r brings up a list of symbols referencing the symbol under the cursor
A list of other LSP-related keymappings are available under goto mode and space mode.
Next steps
- Learn how to work with multiple files in Helix sequentially as well as ways to open multiple files from the command line.
- See the Information about default configurations for each language
- Setup language servers for your specific language, with information available at language server configurations per language.
- To configure formatters for your language, see formatter configurations per language.
- Learn how to use fuzzy finders, workspace symbol search and other useful pickers.