xiaoqiang

xiaoqiang

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"}

Most Liked Responses

xiaoqiang

xiaoqiang

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"}
tcoopman

tcoopman

I’ve figured out a great trick, to be able to run mix test with filename and line numbers as longs a https://github.com/helix-editor/helix/pull/6979 is not merged yet.

I’m using zellij, wezterm and helix of course.

  1. I use this script to parse the file and line number from the terminal:
        set -x

        status_line=$(wezterm cli get-text | rg -e "(?:NOR\s+|NORMAL|INS\s+|INSERT|SEL\s+|SELECT)\s+[\x{2800}-\x{28FF}]*\s+(\S*)\s[^│]* (\d+):*.*" -o --replace '$1 $2')
        filename=$(echo $status_line | awk '{ print $1}')
        line_number=$(echo $status_line | awk '{ print $2}')

        case "$1" in
          "file")
            mix test $filename
            ;;
          "line")
            mix test $filename:$line_number
            ;;
          "all")
            mix test
            ;;
        esac

Source: nix-hour/code/29/home.nix at dfe7bfde9dc117b3f2d583eb418f2376f141757a · tweag/nix-hour · GitHub

save it somewhere as executable.

  1. I add these key-bindings in helix:
[keys.normal."t"]
a = ":run-shell-command zellij run -d right -- helix-wezterm-script.sh all"
f = ":run-shell-command zellij run -d right -- helix-wezterm-script.sh file"
l = ":run-shell-command zellij run -d right -- helix-wezterm-script.sh line"

And now you can run tl in a test file and it will run the test on that line in split.

Hopefully this is useful to someone.

joges

joges

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”}

Where Next?

Popular in Dev Env & Tools Top

sodapopcan
I just placed on an order for my first mechanical watch since I last wore one in my mid 20s which was… oh boy, technically decadeS ago (t...
New
xiaoqiang
These past few days, I’ve tried switching from Neovim to Helix, and so far the experience has been great. Compared to neovim, which requi...
New
Cervajz
Code at the speed of thought Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter. It’s also open...
New
AstonJ
Not sure I’m going to upgrade myself yet, but curious what others think: How are you finding it for dev? What are your thoughts of it g...
New
mveytsman
If you use vim, upgrade alchemist.vim to 2.8.0 as soon as possible!! There’s a bug that allows any website to take over your computer. ...
New
law
/an-aside Why is it not completing the module name too? Atom’s does. Also why does it not fill in the arguments with defaults that yo...
New
mkunikow
SpaceVim is a community-driven vim distribution that seeks to provide layer feature, especially for neovim. It offers a variety of layers...
New
Nezteb
I frequently switch between ElixirLS, Lexical, and Next LS in order to test each out and compare/contrast. I decided to create a brief fe...
New
AstonJ
If you use a VPN or are interested in any please vote in the poll - you can select as many options as you want :icon_biggrin: I’ve added...
New
AstonJ
I wasn’t aware ZSH has plugins until @Samjowen mentioned one in the Share an Elixir or dev-env tip a day thread! Oh My Zsh comes bundle...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement