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{
26 "languages": {
27 "Elixir": {
28 "language_servers": [
29 "expert",
30 "!elixir-ls",
31 "!next-ls",
32 "!lexical",
33 "..."
34 ]
35 }
36 }
37}
38```
39
40### Next LS
41
42To switch to `next-ls`, add the following to your `settings.json`:
43
44```json
45{
46 "languages": {
47 "Elixir": {
48 "language_servers": [
49 "next-ls",
50 "!expert",
51 "!elixir-ls",
52 "!lexical",
53 "..."
54 ]
55 }
56 }
57}
58```
59
60### Lexical
61
62To switch to `lexical`, add the following to your `settings.json`:
63
64```json
65{
66 "languages": {
67 "Elixir": {
68 "language_servers": [
69 "lexical",
70 "!expert",
71 "!elixir-ls",
72 "!next-ls",
73 "..."
74 ]
75 }
76 }
77}
78```
79
80## Setting up `elixir-ls`
81
821. Install `elixir`:
83
84```sh
85brew install elixir
86```
87
882. Install `elixir-ls`:
89
90```sh
91brew install elixir-ls
92```
93
943. Restart Zed
95
96> 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`.
97
98### Formatting with Mix
99
100If 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.
101
102```json
103{
104 "languages": {
105 "Elixir": {
106 "format_on_save": {
107 "external": {
108 "command": "mix",
109 "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
110 }
111 }
112 }
113 }
114}
115```
116
117### Additional workspace configuration options
118
119You can pass additional elixir-ls workspace configuration options via lsp settings in `settings.json`.
120
121The following example disables dialyzer:
122
123```json
124"lsp": {
125 "elixir-ls": {
126 "settings": {
127 "dialyzerEnabled": false
128 }
129 }
130}
131```
132
133See [ElixirLS configuration settings](https://github.com/elixir-lsp/elixir-ls#elixirls-configuration-settings) for more options.
134
135### HEEx
136
137Zed 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.
138
139- Tree-sitter: [phoenixframework/tree-sitter-heex](https://github.com/phoenixframework/tree-sitter-heex)