Skip to content

5. Tutorial: Language Support

Nik Revenco edited this page Mar 1, 2025 · 7 revisions

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 the "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 $PATH
Configured debug adapter: dlv
Binary for debug adapter: 'dlv' not found in $PATH
Configured formatter: None
Highlight 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 $PATH
Configured debug adapter: dlv
Binary for debug adapter: 'dlv' not found in $PATH
Configured formatter: None
Highlight 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.

Note: See Troubleshooting LSP if you face issues.

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:

# languages.toml
[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.

Can't find what you're looking for?

If you want to install a language server / formatter which Helix doesn't configure, you've looked at formatters reference and language servers reference but found nothing that helps you, a decent next step is to use GitHub's search feature.

In all likelihood, someone has probably created the same setup that you want to have in Helix. A quick search on GitHub with the query of path:helix/languages.toml yields thousands of results.

If you want to install a formatter like <whatever> and feel like you're stuck, then we recommend searching for e.g. path:helix/languages.toml <whatever> and looking at the results to find out if any of the code samples you find will help you. In all likelihood, you'll succeed!

Once you figure it out, please send us a pull request to add it to the docs!