Helix editor for Elixir Development

These past few days, I’ve tried switching from Neovim to Helix, and so far the experience has been great. Compared to neovim, which requires multiple plugins and configurations, Helix requires very little configuration to start using it for Elixir. Plus, it has a great shortcut key prompts, so if you’ve used vim before, you can quickly get used to it.

In addition to its out-of-the-box features, one of my favorite features of Helix is its multi-selection editing!

Prerequisites:

  • Ensure that elixir-ls is installed and in your path. On macOS, you can use brew install elixir-ls.

Put the following configuration in .config/helix/languages.toml, and happy coding!

[[language]]
name = "elixir"
scope = "source.elixir"
injection-regex = "elixir"
file-types = ["ex", "exs"]
roots = ["mix.exs"]
auto-format = true
diagnostic-severity = "Hint"
comment-token = "#"
indent = {tab-width = 2, unit = " "}
language-server = {command = "elixir-ls"}
15 Likes

Can it do the template coloring in the same files i.e. two different syntaxes in one file? The HEEX stuff?

1 Like

@OvermindDL1 posted about it last year on DT, I gave it a quick go but didn’t have time to use it much after that, it seemed quite basic at the time tho.

I added the link to it in your post :023:

1 Like

Yep, it’s awesome. I’m also using a not yet merged PR which adds a file tree to it, it’s stable and I had no issues with it for a month or so.

1 Like

It is possible because their syntax highlighting uses tree-sitter.

Furthermore, I suggest updating the Elixir configuration to support specific features of the language server in heex. Additionally, I discovered that my understanding of the “injection-regex” configuration item was incorrect, and we may not require it.

[[language]]
name = "elixir"
scope = "source.elixir"
file-types = ["ex", "exs", "heex"]
roots = ["mix.exs"]
auto-format = true
diagnostic-severity = "Hint"
comment-token = "#"
indent = {tab-width = 2, unit = " "}
language-server = {command = "elixir-ls"}
4 Likes

Awesome!

1 Like

Nice, thank you.

Does it deal with umbrella projects well? I noticed that it detects mix.exs but umbrellas have several such files at a different level.

1 Like

Based on current usage, LSP can function normally with Umbrella projects.

I conducted a test using an Umbrella app named “hello” with a subproject at “hello/apps/world”. Only “hello/apps/world/.elixir_ls” was generated, and it seems that “hello/.elixir_ls” was not generated.

I guess that elixir-ls has implemented support for Umbrella projects, even though “mix.exs” exists in the directory.

1 Like

I am just trying to use Helix, does come with dialyzer support?

1 Like

Yep, it does. You will see all the warning right in the editor.

I read the whole tutor this weekend, and I’m all set up. I’m giving it a go this week :slight_smile:

Thanks for sharing!

1 Like

@fceruti - have you got elixir-ls working. I added

[[language]]
name = "elixir"
scope = "source.elixir"
file-types = ["ex", "exs", "heex"]
roots = ["mix.exs"]
auto-format = true
diagnostic-severity = "Hint"
comment-token = "#"
indent = {tab-width = 2, unit = " "}
language-server = {command = "elixir-ls"}

to my languages.toml file but helix did not seem to find it.
helix did not seem to read languages.toml but hx --health elixir still confirms elixir-ls is configured.
Luke Pighetti on youtube https://www.youtube.com/@LukePighetti/videos uses a ~/.config/helix/config.toml file for helix configuration… I added the [[language]] block to config.toml but helix still did not like that…

❯ hx --health elixir
Configured language server: elixir-ls
Binary for language server: /opt/homebrew/bin/elixir-ls
Configured debug adapter: None
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓

but I still dont get helix showing acces to elixir docs when I press space k while on an elixir function.

Do you have elixir-ls installed and added to your $PATH? Are you trying it out from an Elixir project directory?

yes to both… elixirls is under /opt/homebrew/bin and that is in my $PATH…
I will do another check but not sure what else to try…

Well maybe that’s what you meant, but here you mention elixirls whereas in your config it’s elixir-ls, with a hyphen. In my config it’s without a hyphen.

Thats true - it does show elixir-ls not elixirls.
but… this lists elixir-ls

[[language]]
name = "elixir"
scope = "source.elixir"
file-types = ["ex", "exs", "heex"]
roots = ["mix.exs"]
auto-format = true
diagnostic-severity = "Hint"
comment-token = "#"
indent = {tab-width = 2, unit = " "}
language-server = {command = "**elixir-ls**"}

and so does this…

❯ hx --health elixir
Configured language server: **elixir-ls**
Binary for language server: /opt/homebrew/bin/elixir-ls
Configured debug adapter: None
Highlight queries: ✓
Textobject queries: ✓
Indent queries: ✓

its going to be something silly I expect

The [[language]] block belongs to languages.toml, not to config.toml. See if that helps.

1 Like

But which command launches the LS and which returns “command not found”? Try it out in the terminal.

 ❯❯❯  elixir-ls
elixir-ls: command not found

 ❯❯❯  elixirls
Content-Length: 103

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.13.0","type":3}}Content-Length: 130

Thanks for sticking with this…
I tried this on various paths
home dir
❯ elixir-ls
Content-Length: 103

{“jsonrpc”:“2.0”,“method”:“window/logMessage”,“params”:{“message”:“Started ElixirLS v0.13.0”,“type”:3}}Content-Length: 130

~/.config/helix 14:19:03
❯ elixir-ls
Content-Length: 103

{“jsonrpc”:“2.0”,“method”:“window/logMessage”,“params”:{“message”:“Started ElixirLS v0.13.0”,“type”:3}}Content-Length: 130

/opt/homebrew/bin stable 12:34:04
❯ elixir-ls
Content-Length: 103

{“jsonrpc”:“2.0”,“method”:“window/logMessage”,“params”:{“message”:“Started ElixirLS v0.13.0”,“type”:3}}Content-Length: 130

if i try elixirls I get…

/opt/homebrew/bin stable 14:18:37
❯ elixirls
zsh: command not found: elixirls

❯ elixirls
zsh: command not found: elixirls

So both the config and the binary are fine, good. When you open a .ex file in an Elixir project dir in Helix, and type command :lsp-restart, what do you see in the lower-left corner?