configuring-languages.md

  1---
  2title: Language Server and Tree-sitter Config - Zed
  3description: Configure language support in Zed with Tree-sitter for syntax highlighting and LSP for diagnostics, completion, and formatting.
  4---
  5
  6# Configuring Supported Languages
  7
  8Zed's language support is built on two technologies:
  9
 101. **Tree-sitter** handles syntax highlighting and structure-based features like the outline panel.
 112. **Language Server Protocol (LSP)** provides semantic features: code completion, diagnostics, go-to-definition, and refactoring.
 12
 13This page covers language-specific settings, file associations, language server configuration, formatting, linting, and syntax highlighting.
 14
 15For a list of supported languages, see [Supported Languages](./languages.md). To add support for new languages, see [Language Extensions](./extensions/languages.md).
 16
 17## Language-specific Settings
 18
 19Zed allows you to override global settings for individual languages. These custom configurations are defined in your `settings.json` file under the `languages` key.
 20
 21Here's an example of language-specific settings:
 22
 23```json [settings]
 24"languages": {
 25  "Python": {
 26    "tab_size": 4,
 27    "formatter": "language_server",
 28    "format_on_save": "on"
 29  },
 30  "JavaScript": {
 31    "tab_size": 2,
 32    "formatter": {
 33      "external": {
 34        "command": "prettier",
 35        "arguments": ["--stdin-filepath", "{buffer_path}"]
 36      }
 37    }
 38  }
 39}
 40```
 41
 42You can customize a wide range of settings for each language, including:
 43
 44- [`tab_size`](./reference/all-settings.md#tab-size): The number of spaces for each indentation level
 45- [`formatter`](./reference/all-settings.md#formatter): The tool used for code formatting
 46- [`format_on_save`](./reference/all-settings.md#format-on-save): Whether to automatically format code when saving
 47- [`enable_language_server`](./reference/all-settings.md#enable-language-server): Toggle language server support
 48- [`hard_tabs`](./reference/all-settings.md#hard-tabs): Use tabs instead of spaces for indentation
 49- [`preferred_line_length`](./reference/all-settings.md#preferred-line-length): The recommended maximum line length
 50- [`soft_wrap`](./reference/all-settings.md#soft-wrap): How to wrap long lines of code
 51- [`show_completions_on_input`](./reference/all-settings.md#show-completions-on-input): Whether or not to show completions as you type
 52- [`show_completion_documentation`](./reference/all-settings.md#show-completion-documentation): Whether to display inline and alongside documentation for items in the completions menu
 53- [`colorize_brackets`](./reference/all-settings.md#colorize-brackets): Whether to use tree-sitter bracket queries to detect and colorize the brackets in the editor (also known as "rainbow brackets")
 54
 55These settings allow you to maintain specific coding styles across different languages and projects.
 56
 57## File Associations
 58
 59Zed automatically detects file types based on their extensions, but you can customize these associations to fit your workflow.
 60
 61To set up custom file associations, use the [`file_types`](./reference/all-settings.md#file-types) setting in your `settings.json`:
 62
 63```json [settings]
 64"file_types": {
 65  "C++": ["c"],
 66  "TOML": ["MyLockFile"],
 67  "Dockerfile": ["Dockerfile*"]
 68}
 69```
 70
 71This configuration tells Zed to:
 72
 73- Treat `.c` files as C++ instead of C
 74- Recognize files named "MyLockFile" as TOML
 75- Apply Dockerfile syntax to any file starting with "Dockerfile"
 76
 77You can use glob patterns for more flexible matching, allowing you to handle complex naming conventions in your projects.
 78
 79## Working with Language Servers
 80
 81Language servers are a crucial part of Zed's intelligent coding features, providing capabilities like auto-completion, go-to-definition, and real-time error checking.
 82
 83### What are Language Servers?
 84
 85Language servers implement the Language Server Protocol (LSP), which standardizes communication between the editor and language-specific tools. This allows Zed to support advanced features for multiple programming languages without implementing each feature separately.
 86
 87Some key features provided by language servers include:
 88
 89- Code completion
 90- Error checking and diagnostics
 91- Code navigation (go to definition, find references)
 92- Code actions (Rename, extract method)
 93- Hover information
 94- Workspace symbol search
 95
 96### Managing Language Servers
 97
 98Zed simplifies language server management for users:
 99
1001. Automatic Download: When you open a file with a matching file type, Zed automatically downloads the appropriate language server. Zed may prompt you to install an extension for known file types.
101
1022. Storage Location:
103
104   - macOS: `~/Library/Application Support/Zed/languages`
105   - Linux: `$XDG_DATA_HOME/zed/languages`, `$FLATPAK_XDG_DATA_HOME/zed/languages`, or `$HOME/.local/share/zed/languages`
106
1073. Automatic Updates: Zed keeps your language servers up-to-date, ensuring you always have the latest features and improvements.
108
109### Choosing Language Servers
110
111Some languages in Zed offer multiple language server options. You might have multiple extensions installed that bundle language servers targeting the same language, potentially leading to overlapping capabilities. To ensure you get the functionality you prefer, Zed allows you to prioritize which language servers are used and in what order.
112
113You can specify your preference using the `language_servers` setting:
114
115```json [settings]
116  "languages": {
117    "PHP": {
118      "language_servers": ["intelephense", "!phpactor", "!phptools", "..."]
119    }
120  }
121```
122
123In this example:
124
125- `intelephense` is set as the primary language server.
126- `phpactor` and `phptools` are disabled (note the `!` prefix).
127- `"..."` expands to the rest of the language servers registered for PHP that are not already listed.
128
129The `"..."` entry acts as a wildcard that includes any registered language server you haven't explicitly mentioned. Servers you list by name keep their position, and `"..."` fills in the remaining ones at that point in the list. Servers prefixed with `!` are excluded entirely. This means that if a new language server extension is installed or a new server is registered for a language, `"..."` will automatically include it. If you want full control over which servers are enabled, omit `"..."` — only the servers you list by name will be used.
130
131#### Examples
132
133Suppose you're working with Ruby. The default configuration is:
134
135```json [settings]
136{
137  "language_servers": [
138    "solargraph",
139    "!ruby-lsp",
140    "!rubocop",
141    "!sorbet",
142    "!steep",
143    "!kanayago",
144    "..."
145  ]
146}
147```
148
149When you override `language_servers` in your settings, your list **replaces** the default entirely. This means default-disabled servers like `kanayago` will be re-enabled by `"..."` unless you explicitly disable them again.
150
151| Configuration                                     | Result                                                             |
152| ------------------------------------------------- | ------------------------------------------------------------------ |
153| `["..."]`                                         | `solargraph`, `ruby-lsp`, `rubocop`, `sorbet`, `steep`, `kanayago` |
154| `["ruby-lsp", "..."]`                             | `ruby-lsp`, `solargraph`, `rubocop`, `sorbet`, `steep`, `kanayago` |
155| `["ruby-lsp", "!solargraph", "!kanayago", "..."]` | `ruby-lsp`, `rubocop`, `sorbet`, `steep`                           |
156| `["ruby-lsp", "solargraph"]`                      | `ruby-lsp`, `solargraph`                                           |
157
158> Note: In the first example, `"..."` includes `kanayago` even though it is disabled by default. The override replaced the default list, so the `"!kanayago"` entry is no longer present. To keep it disabled, you must include `"!kanayago"` in your configuration.
159
160### Toolchains
161
162Some language servers need to be configured with a current "toolchain", which is an installation of a specific version of a programming language compiler or/and interpreter, which can possibly include a full set of dependencies of a project.
163An example of what Zed considers a toolchain is a virtual environment in Python.
164Not all languages in Zed support toolchain discovery and selection, but for those that do, you can specify the toolchain from a toolchain picker (via {#action toolchain::Select}). To learn more about toolchains in Zed, see [`toolchains`](./toolchains.md).
165
166### Configuring Language Servers
167
168When configuring language servers in your `settings.json`, autocomplete suggestions include all available LSP adapters recognized by Zed, not only those currently active for loaded languages. This helps you discover and configure language servers before opening files that use them.
169
170Many language servers accept custom configuration options. You can set these in the `lsp` section of your `settings.json`:
171
172```json [settings]
173  "lsp": {
174    "rust-analyzer": {
175      "initialization_options": {
176        "check": {
177          "command": "clippy"
178        }
179      }
180    }
181  }
182```
183
184This example configures the Rust Analyzer to use Clippy for additional linting when saving files.
185
186#### Nested objects
187
188When configuring language server options in Zed, it's important to use nested objects rather than dot-delimited strings. This is particularly relevant when working with more complex configurations. Let's look at a real-world example using the TypeScript language server:
189
190Suppose you want to configure the following settings for TypeScript:
191
192- Enable strict null checks
193- Set the target ECMAScript version to ES2020
194
195Here's how you would structure these settings in Zed's `settings.json`:
196
197```json [settings]
198"lsp": {
199  "typescript-language-server": {
200    "initialization_options": {
201      // These are not supported (VSCode dotted style):
202      // "preferences.strictNullChecks": true,
203      // "preferences.target": "ES2020"
204      //
205      // These is correct (nested notation):
206      "preferences": {
207        "strictNullChecks": true,
208        "target": "ES2020"
209      },
210    }
211  }
212}
213```
214
215#### Possible configuration options
216
217Depending on how a particular language server is implemented, they may depend on different configuration options, both specified in the LSP.
218
219- [initializationOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#version_3_17_0)
220
221Sent once during language server startup, requires server's restart to reapply changes.
222
223For example, rust-analyzer and clangd rely on this way of configuring only.
224
225```json [settings]
226  "lsp": {
227    "rust-analyzer": {
228      "initialization_options": {
229        "checkOnSave": false
230      }
231    }
232  }
233```
234
235- [Configuration Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)
236
237May be queried by the server multiple times.
238Most of the servers would rely on this way of configuring only.
239
240```json [settings]
241"lsp": {
242  "tailwindcss-language-server": {
243    "settings": {
244      "tailwindCSS": {
245        "emmetCompletions": true,
246      },
247    }
248  }
249}
250```
251
252Apart of the LSP-related server configuration options, certain servers in Zed allow configuring the way binary is launched by Zed.
253
254Language servers are automatically downloaded or launched if found in your path, if you wish to specify an explicit alternate binary you can specify that in settings:
255
256```json [settings]
257  "lsp": {
258    "rust-analyzer": {
259      "binary": {
260        // Whether to fetch the binary from the internet, or attempt to find locally.
261        "ignore_system_version": false,
262        "path": "/path/to/langserver/bin",
263        "arguments": ["--option", "value"],
264        "env": {
265          "FOO": "BAR"
266        }
267      }
268    }
269  }
270```
271
272### Enabling or Disabling Language Servers
273
274You can toggle language server support globally or per-language:
275
276```json [settings]
277  "languages": {
278    "Markdown": {
279      "enable_language_server": false
280    }
281  }
282```
283
284This disables the language server for Markdown files, which can be useful for performance in large documentation projects. You can configure this globally in your `~/.config/zed/settings.json` or inside a `.zed/settings.json` in your project directory.
285
286## Formatting and Linting
287
288Zed provides support for code formatting and linting to maintain consistent code style and catch potential issues early.
289
290### Configuring Formatters
291
292Zed supports both built-in and external formatters. See [`formatter`](./reference/all-settings.md#formatter) docs for more. You can configure formatters globally or per-language in your `settings.json`:
293
294```json [settings]
295"languages": {
296  "JavaScript": {
297    "formatter": {
298      "external": {
299        "command": "prettier",
300        "arguments": ["--stdin-filepath", "{buffer_path}"]
301      }
302    },
303    "format_on_save": "on"
304  },
305  "Rust": {
306    "formatter": "language_server",
307    "format_on_save": "on"
308  }
309}
310```
311
312This example uses Prettier for JavaScript and the language server's formatter for Rust, both set to format on save.
313
314To disable formatting for a specific language:
315
316```json [settings]
317"languages": {
318  "Markdown": {
319    "format_on_save": "off"
320  }
321}
322```
323
324### Setting Up Linters
325
326Linting in Zed is typically handled by language servers. Many language servers allow you to configure linting rules:
327
328```json [settings]
329"lsp": {
330  "eslint": {
331    "settings": {
332      "codeActionOnSave": {
333        "rules": ["import/order"]
334      }
335    }
336  }
337}
338```
339
340This configuration sets up ESLint to organize imports on save for JavaScript files.
341
342To run linter fixes automatically on save:
343
344```json [settings]
345"languages": {
346  "JavaScript": {
347    "formatter": {
348      "code_action": "source.fixAll.eslint"
349    }
350  }
351}
352```
353
354### Formatting Selections
355
356Zed supports formatting only the selected text via `editor: format selections` ({#kb editor::FormatSelections}). How
357this works depends on the configured formatter:
358
359- **Language server**: Sends an LSP range formatting request for each selection. This provides the most precise
360  selection-only formatting.
361- **Prettier**: Uses Prettier's built-in range formatting to format the encompassing range of all selections. Any
362  resulting edits that fall outside the selected ranges are discarded, so only the selected code is modified.
363- **External commands**: External command formatters do not support range formatting and are skipped when formatting
364  selections.
365
366### Integrating Formatting and Linting
367
368Zed allows you to run both formatting and linting on save. Here's an example that uses Prettier for formatting and ESLint for linting JavaScript files:
369
370```json [settings]
371"languages": {
372  "JavaScript": {
373    "formatter": [
374      {
375        "code_action": "source.fixAll.eslint"
376      },
377      {
378        "external": {
379          "command": "prettier",
380          "arguments": ["--stdin-filepath", "{buffer_path}"]
381        }
382      }
383    ],
384    "format_on_save": "on"
385  }
386}
387```
388
389### Troubleshooting
390
391If you encounter issues with formatting or linting:
392
3931. Check Zed's log file for error messages (Use the command palette: `zed: open log`)
3942. Ensure external tools (formatters, linters) are correctly installed and in your PATH
3953. Verify configurations in both Zed settings and language-specific config files (e.g., `.eslintrc`, `.prettierrc`)
396
397## Syntax Highlighting and Themes
398
399Zed offers customization options for syntax highlighting and themes, allowing you to tailor the visual appearance of your code.
400
401### Customizing Syntax Highlighting
402
403Zed uses Tree-sitter grammars for syntax highlighting. Override the default highlighting using the `theme_overrides` setting.
404
405This example makes comments italic and changes the color of strings:
406
407```json [settings]
408"theme_overrides": {
409  "One Dark": {
410    "syntax": {
411      "comment": {
412        "font_style": "italic"
413      },
414      "string": {
415        "color": "#00AA00"
416      }
417    }
418  }
419}
420```
421
422### Selecting and Customizing Themes
423
424Change your theme:
425
4261. Use the theme selector ({#kb theme_selector::Toggle})
4272. Or set it in your `settings.json`:
428
429```json [settings]
430"theme": {
431  "mode": "dark",
432  "dark": "One Dark",
433  "light": "GitHub Light"
434}
435```
436
437Create custom themes by creating a JSON file in `~/.config/zed/themes/`. Zed will automatically detect and make available any themes in this directory.
438
439### Using Theme Extensions
440
441Zed supports theme extensions. Browse and install theme extensions from the Extensions panel ({#kb zed::Extensions}).
442
443To create your own theme extension, refer to the [Developing Theme Extensions](./extensions/themes.md) guide.
444
445## Using Language Server Features
446
447### Semantic Tokens
448
449Semantic tokens provide richer syntax highlighting by using type and scope information from language servers. Enable them with the `semantic_tokens` setting:
450
451```json [settings]
452"semantic_tokens": "combined"
453```
454
455- `"off"` — Tree-sitter highlighting only (default)
456- `"combined"` — LSP semantic tokens overlaid on tree-sitter
457- `"full"` — LSP semantic tokens replace tree-sitter entirely
458
459You can customize token colors and styles through `global_lsp_settings.semantic_token_rules` in your settings.
460
461→ [Semantic Tokens documentation](./semantic-tokens.md)
462
463### Inlay Hints
464
465Inlay hints provide additional information inline in your code, such as parameter names or inferred types. Configure inlay hints in your `settings.json`:
466
467```json [settings]
468"inlay_hints": {
469  "enabled": true,
470  "show_type_hints": true,
471  "show_parameter_hints": true,
472  "show_other_hints": true
473}
474```
475
476For language-specific inlay hint settings, refer to the documentation for each language.
477
478### Code Actions
479
480Code actions provide quick fixes and refactoring options. Access code actions using the `editor: Toggle Code Actions` command or by clicking the lightbulb icon that appears next to your cursor when actions are available.
481
482### Go To Definition and References
483
484Use these commands to navigate your codebase:
485
486- `editor: Go to Definition` (<kbd>f12|f12</kbd>)
487- `editor: Go to Type Definition` (<kbd>cmd-f12|ctrl-f12</kbd>)
488- `editor: Find All References` (<kbd>shift-f12|shift-f12</kbd>)
489
490### Rename Symbol
491
492To rename a symbol across your project:
493
4941. Place your cursor on the symbol
4952. Use the `editor: Rename Symbol` command (<kbd>f2|f2</kbd>)
4963. Enter the new name and press Enter
497
498These features depend on the capabilities of the language server for each language.
499
500When renaming a symbol that spans multiple files, Zed will open a preview in a multibuffer. This allows you to review all the changes across your project before applying them. To confirm the rename, simply save the multibuffer. If you decide not to proceed with the rename, you can undo the changes or close the multibuffer without saving.
501
502### Hover Information
503
504Use the `editor: Hover` command to display information about the symbol under the cursor. This often includes type information, documentation, and links to relevant resources.
505
506### Workspace Symbol Search
507
508The {#action project_symbols::Toggle} command allows you to search for symbols (functions, classes, variables) across your entire project. This is useful for quickly navigating large codebases.
509
510### Code Completion
511
512Zed provides intelligent code completion suggestions as you type. You can manually trigger completion with the `editor: Show Completions` command. Use <kbd>tab|tab</kbd> or <kbd>enter|enter</kbd> to accept suggestions.
513
514### Diagnostics
515
516Language servers provide real-time diagnostics (errors, warnings, hints) as you code. View all diagnostics for your project using the {#action diagnostics::Deploy} command.