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