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

AstonJ
Do we have any frequent travellers or digital nomads here? If so where have you been and do you have any tips to share? (Particularly in...
New
hq1
Hey! Just wanted to share my ExUnit NeoVim plugin: GitHub - aerosol/nvim-exunit: Opinionated ExUnit test runner for NeoVim · GitHub The...
New
bwlang
I want to buld this docker image but it fails with a timeout at RUN mix local.hex --force Maybe it’s just a maintenance window, but the...
New
Tyson
I know there are lot of shell-theme nerds in this group. I want to share a little something that Claude and I have been working on in our...
New
mhanberg
Hi y’all! I have started a dedicated Elixir plugin for Neovim. It is still early days, but please check it! GitHub - elixir-tools/elixir...
New
AstonJ
macOS had always used your Account Name as your Username (Case-Preserving) but from around Catalina onwards it started downcasing usernam...
New
AstonJ
Following on from this post in Do you use LittleSnitch or the equivalent on your OS? I think it might be worth us creating this thread so...
New
AstonJ
How fast is your internet connection? (And how much do you pay?) You can test via www.speedtest.net and to embed results into your post...
New
AstonJ
Welcome to our thread for Linux users :smiley: Mac users please use this thread Windows users please use this thread For those who dis...
New
Eiji
Here is my personal list: Real multi-thread support. Panel, sidebar or file tab should not freeze whole app and OS. Access to symbo...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement