DEV Community

Cover image for Setting up Zed for Elixir development πŸ’§
Paulo Henrique da Silva
Paulo Henrique da Silva

Posted on

Setting up Zed for Elixir development πŸ’§

TL; DR: In this article, I describe how I setup zed to develop in elixir and phoenix framework, and here is the gist having the settings I use

It's been a while since I use VS Code to develop elixir applications, and so far, it has been a great tool, especially when using extensions like ElixirLS, Phoenix Framework, Jump to Test, and others.
But like all tools, it has some bottlenecks, and for me, the bottleneck is when working with large projects, where I need to switch between branches multiple times during the day.
Because of that, I started to search for alternatives, and Zed seemed to be the new hype. Don't get me wrong. I know many developers love Vim, but I'm a UI boy and haven't had good experiences with it; I know it's a great editor, but it's just not my thing πŸ˜….
So, let's go back to Zed. To install it, you can use package managers like homebrew or download it directly from their website.
To download by homebrew, you can use the following command:

$ brew install --cask zed  && zed
Enter fullscreen mode Exit fullscreen mode

That's it; you have Zed installed; now let's configure it for Elixir development!
One of the most important tools, at least for me, is the language server, which helps with auto-complete, lint validations, and formatting. Currently, elixir has three options, elixir-ls, lexical, and next-ls. All three are great, and each one has your strength and weakness, I know that there are plans to have a new one that has the goal to be a join of those three to have a LS to rule them all, looking forward to it πŸ˜ƒ.
But until this day doesn't come, I personally prefer ElixirLS, that comes as default on Zed; in my experience, it tends to be more stable when working with large projects, but that's me, you may find that prefers lexical or next-ls, this last one for example allows you to setup credo warnings to be shown in the code, which is pretty cool.
To setup a language server, use the shortcut cmd + shift + P and type and select the option zed: open settings, and add the following code:

"languages": {
  "Elixir": {
    "language_servers": ["elixir-ls"] // <- `next-ls` or `lexical`
  }
}
Enter fullscreen mode Exit fullscreen mode

Then, you can setup the specifics based on what language server you prefer, for ElixirLS, I like to turn off dialyzer when developing and let CIs like CircleCI or Github Actions to run that for me when I push the branch, to do so, you can add lsp config like below:

"lsp": {
  "elixir-ls": {
    "settings": {
      "dialyzerEnabled": false
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Pretty easy, right? Now, let's set up the second most important tool for me: code formatting. And here is where I think vscode is better, again, maybe is because I used to work on large projects, but the format on save on zed has some latency, which on vscode is inexistent, but maybe I'm doing something wrong, happy to chat with you guys about it on comments. But here is the snippet we need to add to enable auto format on zed:

"languages": {
  "Elixir": {
    "format_on_save": {
      "external": {
        "command": "mix",
        "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

At this stage, you have the minimum requirement to start developing in elixir on Zed; now let's go into specifics, HEEX:

"languages": {
  "HEEX": {
    "format_on_save": {
      "external": {
        "command": "mix",
        "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
      }
    },
    "language_servers": [
      "elixir-ls",
      "tailwindcss-language-server",
      "emmet-language-server"
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

In the snippet above, we're setting up heex to format using mix format, elixir-ls, for elixir code that may be inside of the heex files, tailwindcss-language-server, to have tailwind classes auto-complete, and emmet-language-server, to have auto-complete for HTML (i.e. div.flex to be converted to <div class="flex"></div>).
One caveat about Emmet, you may need to do a workaround to make it work as expected. First, use cmd + shift + P, and select option zed: extensions, and install Emmet extension. Once you install it, open and edit the file ~/Library/Application\ Support/Zed/extensions/installed/emmet/extension.toml to reference heex extension:

[language_servers.emmet-language-server]
language = "HTML"
languages = ["HTML", "PHP", "ERB", "JavaScript", "TSX", "CSS", "HEEX"]

[language_servers.emmet-language-server.language_ids]
HEEX = "heex"
Enter fullscreen mode Exit fullscreen mode

Well, that's pretty much it; thank you for reading this! I hope this was useful for you. If you like it or have suggestions on how I can improve this post, please leave a comment; I'll be glad to know that this is being helpful πŸ˜„.
Here's the gist having my Zed config, where I'm going to keep updating when learning more about it.

Cheers!

Top comments (1)

Collapse
 
maiconsilvestre profile image
Maicon Silvestre

Thanks for the tip Paulo, I've been using VIM and VSCode since the beginning, I'm going to test ZED and see how it will perform.