Helix editor for Elixir Development

Also, try 1) removing languages.toml altogether and see if helps and 2) try substituting your languages.toml with the one from here.

Its Working!!! no idea why its just started. - i tried a different elixir project - thats all.

I dont have a languages.toml so I must be using the builtin elixirls

When you press space k how do jump into the docs and scroll through to links like you can in vscode?

have you got Mix format working too by any chance?

I tried lsp-restart and it just says – Language server exited - but elixirls is still working with space k

thanks cloudyday for your help - I can move on now and start learning how to use hx for elixir projects. I am hoping it will get rid of the massive memory hogging I get when I have mutiple vscode windows open.

I tried lsp-restart and it just says – Language server exited

Yeah that’s exactly what you want to see, so all good.

I dont have a languages.toml

But that’s where you’re supposed to put the Helix configuration for Elixir, so where did you put it, then? It should be ~/.config/helix/languages.toml.

When you press space k how do jump into the docs and scroll through to links like you can in vscode?

You can’t follow the links in the docs, but you can scroll them via Ctrl+U (up) and Ctrl+D (down). And to view the source of something, you can gd with the cursor on top of it. See a cheat sheet and the full keymap.

have you got Mix format working too by any chance?

Yeah I don’t actually use it but it works by typing :format. You can also add auto-format = true to you languages.toml so that it formats on each file save automatically. Nice to see it worked out for you, you’re welcome :slight_smile:

But that’s where you’re supposed to put the Helix configuration for Elixir, so where did you put it, then? It should be ~/.config/helix/languages.toml.

I guess that hx is using the builtin elixirls config found in the repo link you sent me helix/languages.toml

but I had tried adding the languages.toml to ~/.config/helix when following the initial instructions in this thread.

@ aiwaiwa
I have now added a languages.toml and merged the settings from helix/languages.toml with this threads settings.

~/.config/helix 8m 39s 16:15:54
❯ ls
config.toml languages.toml

Languages.toml now looks like this…
[[language]]
name = “elixir”
scope = “source.elixir”
injection-regex = “(elixir|ex)”
file-types = [“ex”, “exs”, “heex”]
shebangs = [“elixir”]
roots = [“mix.exs”]
auto-format = true
diagnostic-severity = “Hint”
comment-token = “#”
indent = {tab-width = 2, unit = " "}
language-server = {command = “elixir-ls”}
config = { elixirLS.dialyzerEnabled = false }

my config.toml looks like this and are settings from https://www.youtube.com/@LukePighetti/videos

its still working… tried Ctrl+U (up) and Ctrl+D (down) and gd

Glad to hear it’s working!

It seems your ElixirLS is a bit old (0.14.3 is the latest), may be you could build it from source. It’s quite straightforward.

That’s exactly the configuration you want. If you wish to add more languages, you add their configuration to the same languages.toml file. If you’re interested, here are some extra keymaps that I’ve added to my ~/.config/helix/config.toml:

# ----- Keymaps
[keys.normal]
C-s = ":w" # Save files with Ctrl+S (not sure what that would be on Macs)
C-o = ":open ~/.config/helix/config.toml" # Ctrl+O to open the config
g = { a = "code_action" } # ga to open code actions
X = "extend_line_above" # Shift+x to select the whole line above
D = ["goto_first_nonwhitespace", "extend_to_line_end", "change_selection"] # Wipe and edit the current line
c = ["trim_selections", "change_selection"] # Make 'c' automatically strip the selection of extra whitespace
a = ["append_mode", "collapse_selection"] # Remove the selection when entering insert mode with 'a'
"tab" = "goto_next_function" # Select and jump to the next function via Treesitter
"S-tab" = "goto_prev_function" # Select and jump to the previous function via Treesitter

Happy coding!

added…to config.toml [keys.normal] section

[keys.normal]
esc = ["collapse_selection", "keep_primary_selection"]
ret = ["move_line_down", "goto_first_nonwhitespace"]
0   = "goto_line_start"
C-s = ":w" # Save files with Ctrl+S (not sure what that would be on Macs)
C-o = ":open ~/.config/helix/config.toml" # Ctrl+O to open the config
g = { a = "code_action" } # ga to open code actions
X = "extend_line_above" # Shift+x to select the whole line above
D = ["goto_first_nonwhitespace", "extend_to_line_end", "change_selection"] # Wipe and edit the current line
c = ["trim_selections", "change_selection"] # Make 'c' automatically strip the selection of extra whitespace
a = ["append_mode", "collapse_selection"] # Remove the selection when entering insert mode with 'a'
"tab" = "goto_next_function" # Select and jump to the next function via Treesitter
"S-tab" = "goto_prev_function" # Select and jump to the previous function via Treesitter

thanks

I did find a link to adding ElixiLS from source yesterday but I have so many tabs open its got lost - I will find it somewhere…

There are also prebuilt binaries available at Releases · elixir-lsp/elixir-ls · GitHub. But do note that once you either compile one yourself or download a prebuilt one, you will end up with a .sh launcher which you will need to create a symlink for and make sure this symlink is available in your path. For example, I downloaded a prebuilt release and put the zip contents into ~/.local/share/elixirls, then created a symlink to ~/.local/share/elixirls/language_server.sh and put it into ~/.local/bin (which is in my $PATH).

I installed it and went over the tutor. Didn’t try it on a project yet. So far it looks good. Never heard of this editor so thanks for the post!

1 Like

BTW there’s also a “Helix mode” extension for VS code. I’ve just tried it and it’s surprisingly good, the only flaw I noticed so far is deleting the wrong bracket pairs upon typing md(. Good to know because I really needed to combine the wide reach of VSC plugins and ergonomics of Helix (vim feels painful for me).

1 Like

I always get Async job failed , it did work once but never again right now it works for ruby and docker in my env but for elixir it fails even though I can run elixis-ls from cli or using sh in helix but the lsp doesn’t work in editor. Anyone else seen this issue ?

image
image

image
image

I always wanted to try helix, I come from 15 years of vim and 1 year of neovim.
Are you using exclusively helix or are you switching between the two?
I fear I can’t really learn helix if I still use vim most of the time…

There’s no need to worry, they are all pattern-based editors and I think it’s very easy to switch to Helix.

My current situation is that I still switch between the two because the PR for Helix’s file tree hasn’t been merged yet, and sometimes it’s not convenient for me to browse the file structure in Helix.

I haven’t met that, but I believe we can try to add timeout in .config/helix/languages.toml
https://docs.helix-editor.com/languages.html

[[language-server]]
timeout = 30

I noticed that the syntax highlighting for HEEX files was not correct with just adding “heex” to the file types but adding “html.heex” did the trick for me:

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

3 Likes

I noted that after installing on a system that I had not been doing elixir development on, I had to run the language server executable directly to clear the Y/N questions it was asking before it would work with Helix.

I also want to run elixir in helix. But for me its working.

I notice that hx/elixir-ls work in elixir 1.14, because that’s the version i compiled elixir-ls with on ubuntu, but it does not work with elixir 1.13. Anyone know how to deal with that?

I too couldn’t make elixir-ls work even though I followed the installation steps correctly, what solved it for me was starting elixir-ls from the command line and installing Hex (or whatever dependency it prompted to install).