elixir.md

  1# Elixir
  2
  3Elixir support is available through the [Elixir extension](https://github.com/zed-extensions/elixir).
  4
  5- Tree-sitter:
  6  - [elixir-lang/tree-sitter-elixir](https://github.com/elixir-lang/tree-sitter-elixir)
  7  - [phoenixframework/tree-sitter-heex](https://github.com/phoenixframework/tree-sitter-heex)
  8- Language servers:
  9  - [elixir-lang/expert](https://github.com/elixir-lang/expert)
 10  - [elixir-lsp/elixir-ls](https://github.com/elixir-lsp/elixir-ls)
 11  - [elixir-tools/next-ls](https://github.com/elixir-tools/next-ls)
 12  - [lexical-lsp/lexical](https://github.com/lexical-lsp/lexical)
 13
 14## Choosing a language server
 15
 16The Elixir extension offers language server support for `expert`, `elixir-ls`, `next-ls`, and `lexical`.
 17
 18`elixir-ls` is enabled by default.
 19
 20### Expert
 21
 22To switch to `expert`, add the following to your `settings.json`:
 23
 24```json
 25  "languages": {
 26    "Elixir": {
 27      "language_servers": ["expert", "!elixir-ls", "!next-ls", "!lexical", "..."]
 28    },
 29    "HEEX": {
 30      "language_servers": ["expert", "!elixir-ls", "!next-ls", "!lexical", "..."]
 31    }
 32  }
 33```
 34
 35### Next LS
 36
 37To switch to `next-ls`, add the following to your `settings.json`:
 38
 39```json
 40  "languages": {
 41    "Elixir": {
 42      "language_servers": ["next-ls", "!expert", "!elixir-ls", "!lexical", "..."]
 43    },
 44    "HEEX": {
 45      "language_servers": ["next-ls", "!expert", "!elixir-ls", "!lexical", "..."]
 46    }
 47  }
 48```
 49
 50### Lexical
 51
 52To switch to `lexical`, add the following to your `settings.json`:
 53
 54```json
 55  "languages": {
 56    "Elixir": {
 57      "language_servers": ["lexical", "!expert", "!elixir-ls", "!next-ls", "..."]
 58    },
 59    "HEEX": {
 60      "language_servers": ["lexical", "!expert", "!elixir-ls", "!next-ls", "..."]
 61    }
 62  }
 63```
 64
 65## Setting up `elixir-ls`
 66
 671. Install `elixir`:
 68
 69```sh
 70brew install elixir
 71```
 72
 732. Install `elixir-ls`:
 74
 75```sh
 76brew install elixir-ls
 77```
 78
 793. Restart Zed
 80
 81> If `elixir-ls` is not running in an elixir project, check the error log via the command palette action `zed: open log`. If you find an error message mentioning: `invalid LSP message header "Shall I install Hex? (if running non-interactively, use \"mix local.hex --force\") [Yn]`, you might need to install [`Hex`](https://hex.pm). You run `elixir-ls` from the command line and accept the prompt to install `Hex`.
 82
 83### Formatting with Mix
 84
 85If you prefer to format your code with [Mix](https://hexdocs.pm/mix/Mix.html), use the following snippet in your `settings.json` file to configure it as an external formatter. Formatting will occur on file save.
 86
 87```json
 88{
 89  "languages": {
 90    "Elixir": {
 91      "format_on_save": {
 92        "external": {
 93          "command": "mix",
 94          "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
 95        }
 96      }
 97    }
 98  }
 99}
100```
101
102### Additional workspace configuration options
103
104You can pass additional elixir-ls workspace configuration options via lsp settings in `settings.json`.
105
106The following example disables dialyzer:
107
108```json
109  "lsp": {
110    "elixir-ls": {
111      "settings": {
112        "dialyzerEnabled": false
113      }
114    }
115  }
116```
117
118See [ElixirLS configuration settings](https://github.com/elixir-lsp/elixir-ls#elixirls-configuration-settings) for more options.
119
120### HEEx
121
122Zed also supports HEEx templates. HEEx is a mix of [EEx](https://hexdocs.pm/eex/1.12.3/EEx.html) (Embedded Elixir) and HTML, and is used in Phoenix LiveView applications.
123
124- Tree-sitter: [phoenixframework/tree-sitter-heex](https://github.com/phoenixframework/tree-sitter-heex)