1# Configuring supported languages
2
3Zed offers powerful customization options for each programming language it supports. This guide will walk you through the various ways you can tailor your coding experience to your preferences and project requirements.
4
5Zed's language support is built on two main technologies:
6
71. Tree-sitter: This handles syntax highlighting and structure-based features like the outline panel.
82. Language Server Protocol (LSP): This provides semantic features such as code completion and diagnostics.
9
10These components work together to provide Zed's language capabilities.
11
12In this guide, we'll cover:
13
14- Language-specific settings
15- File associations
16- Working with language servers
17- Formatting and linting configuration
18- Customizing syntax highlighting and themes
19- Advanced language features
20
21By the end of this guide, you should know how to configure and customize supported languages in Zed.
22
23For a comprehensive list of languages supported by Zed and their specific configurations, see our [Supported Languages](./languages.md) page. To go further, you could explore developing your own extensions to add support for additional languages or enhance existing functionality. For more information on creating language extensions, see our [Language Extensions](./extensions/languages.md) guide.
24
25## Language-specific Settings
26
27Zed allows you to override global settings for individual languages. These custom configurations are defined in your `settings.json` file under the `languages` key.
28
29Here's an example of language-specific settings:
30
31```json
32"languages": {
33 "Python": {
34 "tab_size": 4,
35 "formatter": "language_server",
36 "format_on_save": "on"
37 },
38 "JavaScript": {
39 "tab_size": 2,
40 "formatter": {
41 "external": {
42 "command": "prettier",
43 "arguments": ["--stdin-filepath", "{buffer_path}"]
44 }
45 }
46 }
47}
48```
49
50You can customize a wide range of settings for each language, including:
51
52- [`tab_size`](./configuring-zed.md#tab-size): The number of spaces for each indentation level
53- [`formatter`](./configuring-zed.md#formatter): The tool used for code formatting
54- [`format_on_save`](./configuring-zed.md#format-on-save): Whether to automatically format code when saving
55- [`enable_language_server`](./configuring-zed.md#enable-language-server): Toggle language server support
56- [`hard_tabs`](./configuring-zed.md#hard-tabs): Use tabs instead of spaces for indentation
57- [`preferred_line_length`](./configuring-zed.md#preferred-line-length): The recommended maximum line length
58- [`soft_wrap`](./configuring-zed.md#soft-wrap): How to wrap long lines of code
59- [`show_completions_on_input`](./configuring-zed.md#show-completions-on-input): Whether or not to show completions as you type
60- [`show_completion_documentation`](./configuring-zed.md#show-completion-documentation): Whether to display inline and alongside documentation for items in the completions menu
61
62These settings allow you to maintain specific coding styles across different languages and projects.
63
64## File Associations
65
66Zed automatically detects file types based on their extensions, but you can customize these associations to fit your workflow.
67
68To set up custom file associations, use the [`file_types`](./configuring-zed.md#file-types) setting in your `settings.json`:
69
70```json
71"file_types": {
72 "C++": ["c"],
73 "TOML": ["MyLockFile"],
74 "Dockerfile": ["Dockerfile*"]
75}
76```
77
78This configuration tells Zed to:
79
80- Treat `.c` files as C++ instead of C
81- Recognize files named "MyLockFile" as TOML
82- Apply Dockerfile syntax to any file starting with "Dockerfile"
83
84You can use glob patterns for more flexible matching, allowing you to handle complex naming conventions in your projects.
85
86## Working with Language Servers
87
88Language servers are a crucial part of Zed's intelligent coding features, providing capabilities like auto-completion, go-to-definition, and real-time error checking.
89
90### What are Language Servers?
91
92Language 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.
93
94Some key features provided by language servers include:
95
96- Code completion
97- Error checking and diagnostics
98- Code navigation (go to definition, find references)
99- Code actions (Rename, extract method)
100- Hover information
101- Workspace symbol search
102
103### Managing Language Servers
104
105Zed simplifies language server management for users:
106
1071. 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.
108
1092. Storage Location:
110
111 - macOS: `~/Library/Application Support/Zed/languages`
112 - Linux: `$XDG_DATA_HOME/languages`, `$FLATPAK_XDG_DATA_HOME/languages`, or `$HOME/.local/share`
113
1143. Automatic Updates: Zed keeps your language servers up-to-date, ensuring you always have the latest features and improvements.
115
116### Choosing Language Servers
117
118Some 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.
119
120You can specify your preference using the `language_servers` setting:
121
122```json
123 "languages": {
124 "PHP": {
125 "language_servers": ["intelephense", "!phpactor", "..."]
126 }
127 }
128```
129
130In this example:
131
132- `intelephense` is set as the primary language server
133- `phpactor` is disabled (note the `!` prefix)
134- `...` expands to the rest of the language servers that are registered for PHP
135
136This configuration allows you to tailor the language server setup to your specific needs, ensuring that you get the most suitable functionality for your development workflow.
137
138### Configuring Language Servers
139
140Many language servers accept custom configuration options. You can set these in the `lsp` section of your `settings.json`:
141
142```json
143 "lsp": {
144 "rust-analyzer": {
145 "initialization_options": {
146 "check": {
147 "command": "clippy"
148 }
149 }
150 }
151 }
152```
153
154This example configures the Rust Analyzer to use Clippy for additional linting when saving files.
155
156#### Nested objects
157
158When 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:
159
160Suppose you want to configure the following settings for TypeScript:
161
162- Enable strict null checks
163- Set the target ECMAScript version to ES2020
164
165Here's how you would structure these settings in Zed's `settings.json`:
166
167```json
168"lsp": {
169 "typescript-language-server": {
170 "initialization_options": {
171 // These are not supported (VSCode dotted style):
172 // "preferences.strictNullChecks": true,
173 // "preferences.target": "ES2020"
174 //
175 // These is correct (nested notation):
176 "preferences": {
177 "strictNullChecks": true,
178 "target": "ES2020"
179 },
180 }
181 }
182}
183```
184
185#### Possible configuration options
186
187Depending on how a particular language server is implemented, they may depend on different configuration options, both specified in the LSP.
188
189- [initializationOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#version_3_17_0)
190
191Sent once during language server startup, requires server's restart to reapply changes.
192
193For example, rust-analyzer and clangd rely on this way of configuring only.
194
195```json
196 "lsp": {
197 "rust-analyzer": {
198 "initialization_options": {
199 "checkOnSave": false
200 }
201 }
202 }
203```
204
205- [Configuration Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)
206
207May be queried by the server multiple times.
208Most of the servers would rely on this way of configuring only.
209
210```json
211"lsp": {
212 "tailwindcss-language-server": {
213 "settings": {
214 "tailwindCSS": {
215 "emmetCompletions": true,
216 },
217 }
218 }
219}
220```
221
222Apart of the LSP-related server configuration options, certain servers in Zed allow configuring the way binary is launched by Zed.
223
224Language 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:
225
226```json
227 "lsp": {
228 "rust-analyzer": {
229 "binary": {
230 // Whether to fetch the binary from the internet, or attempt to find locally.
231 "ignore_system_version": false,
232 "path": "/path/to/langserver/bin",
233 "arguments": ["--option", "value"],
234 "env": {
235 "FOO": "BAR"
236 }
237 }
238 }
239 }
240```
241
242### Enabling or Disabling Language Servers
243
244You can toggle language server support globally or per-language:
245
246```json
247 "languages": {
248 "Markdown": {
249 "enable_language_server": false
250 }
251 }
252```
253
254This 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.
255
256## Formatting and Linting
257
258Zed provides support for code formatting and linting to maintain consistent code style and catch potential issues early.
259
260### Configuring Formatters
261
262Zed supports both built-in and external formatters. See [`formatter`](./configuring-zed.md#formatter) docs for more. You can configure formatters globally or per-language in your `settings.json`:
263
264```json
265"languages": {
266 "JavaScript": {
267 "formatter": {
268 "external": {
269 "command": "prettier",
270 "arguments": ["--stdin-filepath", "{buffer_path}"]
271 }
272 },
273 "format_on_save": "on"
274 },
275 "Rust": {
276 "formatter": "language_server",
277 "format_on_save": "on"
278 }
279}
280```
281
282This example uses Prettier for JavaScript and the language server's formatter for Rust, both set to format on save.
283
284To disable formatting for a specific language:
285
286```json
287"languages": {
288 "Markdown": {
289 "format_on_save": "off"
290 }
291}
292```
293
294### Setting Up Linters
295
296Linting in Zed is typically handled by language servers. Many language servers allow you to configure linting rules:
297
298```json
299"lsp": {
300 "eslint": {
301 "settings": {
302 "codeActionOnSave": {
303 "rules": ["import/order"]
304 }
305 }
306 }
307}
308```
309
310This configuration sets up ESLint to organize imports on save for JavaScript files.
311
312To run linter fixes automatically on save:
313
314```json
315"languages": {
316 "JavaScript": {
317 "code_actions_on_format": {
318 "source.fixAll.eslint": true
319 }
320 }
321}
322```
323
324### Integrating Formatting and Linting
325
326Zed 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:
327
328```json
329"languages": {
330 "JavaScript": {
331 "formatter": {
332 "external": {
333 "command": "prettier",
334 "arguments": ["--stdin-filepath", "{buffer_path}"]
335 }
336 },
337 "code_actions_on_format": {
338 "source.fixAll.eslint": true
339 },
340 "format_on_save": "on"
341 }
342}
343```
344
345### Troubleshooting
346
347If you encounter issues with formatting or linting:
348
3491. Check Zed's log file for error messages (Use the command palette: `zed: open log`)
3502. Ensure external tools (formatters, linters) are correctly installed and in your PATH
3513. Verify configurations in both Zed settings and language-specific config files (e.g., `.eslintrc`, `.prettierrc`)
352
353## Syntax Highlighting and Themes
354
355Zed offers customization options for syntax highlighting and themes, allowing you to tailor the visual appearance of your code.
356
357### Customizing Syntax Highlighting
358
359Zed uses Tree-sitter grammars for syntax highlighting. Override the default highlighting using the `experimental.theme_overrides` setting.
360
361This example makes comments italic and changes the color of strings:
362
363```json
364"experimental.theme_overrides": {
365 "syntax": {
366 "comment": {
367 "font_style": "italic"
368 },
369 "string": {
370 "color": "#00AA00"
371 }
372 }
373}
374```
375
376### Selecting and Customizing Themes
377
378Change your theme:
379
3801. Use the theme selector ({#kb theme_selector::Toggle})
3812. Or set it in your `settings.json`:
382
383```json
384"theme": {
385 "mode": "dark",
386 "dark": "One Dark",
387 "light": "GitHub Light"
388}
389```
390
391Create custom themes by creating a JSON file in `~/.config/zed/themes/`. Zed will automatically detect and make available any themes in this directory.
392
393### Using Theme Extensions
394
395Zed supports theme extensions. Browse and install theme extensions from the Extensions panel ({#kb zed::Extensions}).
396
397To create your own theme extension, refer to the [Developing Theme Extensions](./extensions/themes.md) guide.
398
399## Using Language Server Features
400
401### Inlay Hints
402
403Inlay hints provide additional information inline in your code, such as parameter names or inferred types. Configure inlay hints in your `settings.json`:
404
405```json
406"inlay_hints": {
407 "enabled": true,
408 "show_type_hints": true,
409 "show_parameter_hints": true,
410 "show_other_hints": true
411}
412```
413
414For language-specific inlay hint settings, refer to the documentation for each language.
415
416### Code Actions
417
418Code 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.
419
420### Go To Definition and References
421
422Use these commands to navigate your codebase:
423
424- `editor: Go to Definition` (<kbd>f12|f12</kbd>)
425- `editor: Go to Type Definition` (<kbd>cmd-f12|ctrl-f12</kbd>)
426- `editor: Find All References` (<kbd>shift-f12|shift-f12</kbd>)
427
428### Rename Symbol
429
430To rename a symbol across your project:
431
4321. Place your cursor on the symbol
4332. Use the `editor: Rename Symbol` command (<kbd>f2|f2</kbd>)
4343. Enter the new name and press Enter
435
436These features depend on the capabilities of the language server for each language.
437
438When 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.
439
440### Hover Information
441
442Use the `editor: Hover` command to display information about the symbol under the cursor. This often includes type information, documentation, and links to relevant resources.
443
444### Workspace Symbol Search
445
446The `workspace: Open Symbol` command allows you to search for symbols (functions, classes, variables) across your entire project. This is useful for quickly navigating large codebases.
447
448### Code Completion
449
450Zed 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.
451
452### Diagnostics
453
454Language servers provide real-time diagnostics (errors, warnings, hints) as you code. View all diagnostics for your project using the `diagnostics: Toggle` command.