1# Elixir
2
3Elixir support is available through the [Elixir extension](https://github.com/zed-industries/zed/tree/main/extensions/elixir).
4
5## Choosing a language server
6
7The Elixir extension offers language server support for `elixir-ls`, `next-ls`, and `lexical`.
8
9`elixir-ls` is enabled by default.
10
11To switch to `next-ls`, add the following to your `settings.json`:
12
13```json
14{
15 "languages": {
16 "Elixir": {
17 "language_servers": ["next-ls", "!elixir-ls", "..."]
18 }
19 }
20}
21```
22
23To switch to `lexical`, add the following to your `settings.json`:
24
25```json
26{
27 "languages": {
28 "Elixir": {
29 "language_servers": ["lexical", "!elixir-ls", "..."]
30 }
31 }
32}
33```
34
35## Setting up `elixir-ls`
36
371. Install `elixir`:
38
39```bash
40brew install elixir
41```
42
432. Install `elixir-ls`:
44
45```bash
46brew install elixir-ls
47```
48
493. Restart Zed
50
51> 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`.
52
53### Formatting with Mix
54
55If 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.
56
57```json
58{
59 "languages": {
60 "Elixir": {
61 "format_on_save": {
62 "external": {
63 "command": "mix",
64 "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
65 }
66 }
67 }
68 }
69}
70```
71
72### Additional workspace configuration options (requires Zed `0.128.0`):
73
74You can pass additional elixir-ls workspace configuration options via lsp settings in `settings.json`.
75
76The following example disables dialyzer:
77
78```json
79"lsp": {
80 "elixir-ls": {
81 "settings": {
82 "dialyzerEnabled": false
83 }
84 }
85}
86```
87
88See [ElixirLS configuration settings](https://github.com/elixir-lsp/elixir-ls#elixirls-configuration-settings) for more options.