elixir.md

  1---
  2title: Elixir
  3description: "Configure Elixir language support in Zed, including language servers, formatting, and debugging."
  4---
  5
  6# Elixir
  7
  8Elixir support is available through the [Elixir extension](https://github.com/zed-extensions/elixir).
  9
 10- Tree-sitter Grammars:
 11  - [elixir-lang/tree-sitter-elixir](https://github.com/elixir-lang/tree-sitter-elixir)
 12  - [phoenixframework/tree-sitter-heex](https://github.com/phoenixframework/tree-sitter-heex)
 13- Language Servers:
 14  - [elixir-lang/expert](https://github.com/elixir-lang/expert)
 15  - [elixir-lsp/elixir-ls](https://github.com/elixir-lsp/elixir-ls)
 16  - [elixir-tools/next-ls](https://github.com/elixir-tools/next-ls)
 17  - [lexical-lsp/lexical](https://github.com/lexical-lsp/lexical)
 18  - [remoteoss/dexter](https://github.com/remoteoss/dexter)
 19
 20Furthermore, the extension provides support for [EEx](https://hexdocs.pm/eex/EEx.html) (Embedded Elixir) templates and [HEEx](https://hexdocs.pm/phoenix/components.html#heex) templates, a mix of HTML and EEx used by Phoenix LiveView applications.
 21
 22## Language Servers
 23
 24The Elixir extension offers language server support for ElixirLS, Expert, Dexter, Next LS, and Lexical. By default, only ElixirLS is enabled. You can change or disable the enabled language servers in your settings ({#kb zed::OpenSettings}) under Languages > Elixir/EEx/HEEx or directly within your settings file.
 25
 26Some of the language servers can also accept initialization or workspace configuration options. See the sections below for an outline of what each server supports. The configuration can be passed in your settings file via `lsp.{language-server-id}.initialization_options` and `lsp.{language-server-id}.settings` respectively.
 27
 28Visit the [Configuring Zed](../configuring-zed.md#settings-files) guide for more information on how to edit your settings file.
 29
 30### Using ElixirLS
 31
 32ElixirLS can accept workspace configuration options.
 33
 34The following example disables [Dialyzer](https://github.com/elixir-lsp/elixir-ls#dialyzer-integration):
 35
 36```json [settings]
 37  "lsp": {
 38    "elixir-ls": {
 39      "settings": {
 40        "dialyzerEnabled": false
 41      }
 42    }
 43  }
 44```
 45
 46See the official list of [ElixirLS configuration settings](https://github.com/elixir-lsp/elixir-ls#elixirls-configuration-settings) for all available options.
 47
 48### Using Expert
 49
 50Enable Expert by adding the following to your settings file:
 51
 52```json [settings]
 53  "languages": {
 54    "Elixir": {
 55      "language_servers": ["expert", "!elixir-ls", "!dexter", "!next-ls", "!lexical", "..."]
 56    },
 57    "EEx": {
 58      "language_servers": ["expert", "!elixir-ls", "!dexter", "!next-ls", "!lexical", "..."]
 59    },
 60    "HEEx": {
 61      "language_servers": ["expert", "!elixir-ls", "!dexter", "!next-ls", "!lexical", "..."]
 62    }
 63  }
 64```
 65
 66Expert can accept workspace configuration options.
 67
 68The following example sets the minimum number of characters required for a project symbol search to return results:
 69
 70```json [settings]
 71  "lsp": {
 72    "expert": {
 73      "settings": {
 74        "workspaceSymbols": {
 75          "minQueryLength": 0
 76        }
 77      }
 78    }
 79  }
 80```
 81
 82See the [Expert configuration](https://expert-lsp.org/docs/configuration/) page for all available options.
 83
 84To use a custom Expert build, add the following to your settings file:
 85
 86```json [settings]
 87  "lsp": {
 88    "expert": {
 89      "binary": {
 90        "path": "/path/to/expert",
 91        "arguments": ["--stdio"]
 92      }
 93    }
 94  }
 95```
 96
 97### Using Dexter
 98
 99[Dexter](https://github.com/remoteoss/dexter) is a fast, full-featured Elixir language server optimized for large codebases. It works by parsing source files directly, no compilation required. Supports go-to-definition, references, hover docs, autocompletion, rename, and format on save.
100
101Enable Dexter by adding the following to your settings file:
102
103```json [settings]
104  "languages": {
105    "Elixir": {
106      "language_servers": ["dexter", "!expert", "!elixir-ls", "!next-ls", "!lexical", "..."]
107    },
108    "EEx": {
109      "language_servers": ["dexter", "!expert", "!elixir-ls", "!next-ls", "!lexical", "..."]
110    },
111    "HEEx": {
112      "language_servers": ["dexter", "!expert", "!elixir-ls", "!next-ls", "!lexical", "..."]
113    }
114  }
115```
116
117Dexter can accept initialization options.
118
119The following example disables following `defdelegate` to the target function:
120
121```json [settings]
122  "lsp": {
123    "dexter": {
124      "initialization_options": {
125        "followDelegates": false
126      }
127    }
128  }
129```
130
131To use a custom Dexter binary, add the following to your settings file:
132
133```json [settings]
134  "lsp": {
135    "dexter": {
136      "binary": {
137        "path": "/path/to/dexter",
138        "arguments": ["lsp"]
139      }
140    }
141  }
142```
143
144See the [Dexter documentation](https://github.com/remoteoss/dexter) for more details.
145
146### Using Next LS
147
148Enable Next LS by adding the following to your settings file:
149
150```json [settings]
151  "languages": {
152    "Elixir": {
153      "language_servers": ["next-ls", "!expert", "!elixir-ls", "!dexter", "!lexical", "..."]
154    },
155    "EEx": {
156      "language_servers": ["next-ls", "!expert", "!elixir-ls", "!dexter", "!lexical", "..."]
157    },
158    "HEEx": {
159      "language_servers": ["next-ls", "!expert", "!elixir-ls", "!dexter", "!lexical", "..."]
160    }
161  }
162```
163
164Next LS can accept initialization options.
165
166Completions are an experimental feature within Next LS, they are enabled by default in Zed. Disable them by adding the following to your settings file:
167
168```json [settings]
169  "lsp": {
170    "next-ls": {
171      "initialization_options": {
172        "experimental": {
173          "completions": {
174            "enable": false
175          }
176        }
177      }
178    }
179  }
180```
181
182Next LS also has an extension for [Credo](https://hexdocs.pm/credo/overview.html) integration which is enabled by default. You can disable this by adding the following section to your settings file:
183
184```json [settings]
185  "lsp": {
186    "next-ls": {
187      "initialization_options": {
188        "extensions": {
189          "credo": {
190            "enable": false
191          }
192        }
193      }
194    }
195  }
196```
197
198Next LS can also pass CLI options directly to Credo. The following example passes `--min-priority high` to it:
199
200```json [settings]
201  "lsp": {
202    "next-ls": {
203      "initialization_options": {
204        "extensions": {
205          "credo": {
206            "cli_options": ["--min-priority high"]
207          }
208        }
209      }
210    }
211  }
212```
213
214See the [Credo Command Line Switches](https://hexdocs.pm/credo/suggest_command.html#command-line-switches) page for more CLI options.
215
216### Using Lexical
217
218Enable Lexical by adding the following to your settings file:
219
220```json [settings]
221  "languages": {
222    "Elixir": {
223      "language_servers": ["lexical", "!expert", "!elixir-ls", "!dexter", "!next-ls", "..."]
224    },
225    "EEx": {
226      "language_servers": ["lexical", "!expert", "!elixir-ls", "!dexter", "!next-ls", "..."]
227    },
228    "HEEx": {
229      "language_servers": ["lexical", "!expert", "!elixir-ls", "!dexter", "!next-ls", "..."]
230    }
231  }
232```
233
234## Formatting without a language server
235
236If you prefer to work without a language server but would still like code formatting from [Mix](https://hexdocs.pm/mix/Mix.html), you can configure it as an external formatter by adding the following to your settings file:
237
238```json [settings]
239  "languages": {
240    "Elixir": {
241      "enable_language_server": false,
242      "format_on_save": "on",
243      "formatter": {
244        "external": {
245          "command": "mix",
246          "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
247        }
248      }
249    },
250    "EEx": {
251      "enable_language_server": false,
252      "format_on_save": "on",
253      "formatter": {
254        "external": {
255          "command": "mix",
256          "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
257        }
258      }
259    },
260    "HEEx": {
261      "enable_language_server": false,
262      "format_on_save": "on",
263      "formatter": {
264        "external": {
265          "command": "mix",
266          "arguments": ["format", "--stdin-filename", "{buffer_path}", "-"]
267        }
268      }
269    }
270  }
271```
272
273## Using the Tailwind CSS Language Server with HEEx templates
274
275To get all features (autocomplete, linting, and hover docs) from the [Tailwind CSS language server](https://github.com/tailwindlabs/tailwindcss-intellisense/tree/HEAD/packages/tailwindcss-language-server#readme) in HEEx templates, add the following to your settings file:
276
277```json [settings]
278  "lsp": {
279    "tailwindcss-language-server": {
280      "settings": {
281        "includeLanguages": {
282          "elixir": "html",
283          "heex": "html"
284        },
285        "experimental": {
286          "classRegex": ["class=\"([^\"]*)\"", "class='([^']*)'"]
287        }
288      }
289    }
290  }
291```
292
293With these settings, you will get completions for Tailwind CSS classes in HEEx templates. Examples:
294
295```heex
296<%!-- Standard class attribute --%>
297<div class="flex items-center <completion here>">
298  <p class="text-lg font-bold <completion here>">Hello World</p>
299</div>
300
301<%!-- With Elixir expression --%>
302<div class={"flex #{@custom_class} <completion here>"}>
303  Content
304</div>
305
306<%!-- With Phoenix function --%>
307<div class={class_list(["flex", "items-center", "<completion here>"])}>
308  Content
309</div>
310```
311
312## See also
313
314- [Erlang](./erlang.md)
315- [Gleam](./gleam.md)