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-lsp/elixir-ls](https://github.com/elixir-lsp/elixir-ls)
10 - [elixir-tools/next-ls](https://github.com/elixir-tools/next-ls)
11 - [lexical-lsp/lexical](https://github.com/lexical-lsp/lexical)
12
13## Choosing a language server
14
15The Elixir extension offers language server support for `elixir-ls`, `next-ls`, and `lexical`.
16
17`elixir-ls` is enabled by default.
18
19To switch to `next-ls`, add the following to your `settings.json`:
20
21```json
22{
23 "languages": {
24 "Elixir": {
25 "language_servers": ["next-ls", "!elixir-ls", "..."]
26 }
27 }
28}
29```
30
31To switch to `lexical`, add the following to your `settings.json`:
32
33```json
34{
35 "languages": {
36 "Elixir": {
37 "language_servers": ["lexical", "!elixir-ls", "..."]
38 }
39 }
40}
41```
42
43## Setting up `elixir-ls`
44
451. Install `elixir`:
46
47```sh
48brew install elixir
49```
50
512. Install `elixir-ls`:
52
53```sh
54brew install elixir-ls
55```
56
573. Restart Zed
58
59> 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`.
60
61### Formatting with Mix
62
63If 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.
64
65```json
66{
67 "languages": {
68 "Elixir": {
69 "format_on_save": {
70 "external": {
71 "command": "mix",
72 "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
73 }
74 }
75 }
76 }
77}
78```
79
80### Additional workspace configuration options
81
82You can pass additional elixir-ls workspace configuration options via lsp settings in `settings.json`.
83
84The following example disables dialyzer:
85
86```json
87"lsp": {
88 "elixir-ls": {
89 "settings": {
90 "dialyzerEnabled": false
91 }
92 }
93}
94```
95
96See [ElixirLS configuration settings](https://github.com/elixir-lsp/elixir-ls#elixirls-configuration-settings) for more options.
97
98### HEEx
99
100Zed 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.
101
102- Tree-sitter: [phoenixframework/tree-sitter-heex](https://github.com/phoenixframework/tree-sitter-heex)