To set up custom file associations, use the [`file_types`](./configuring-zed.md#file-types) setting in your `settings.json`:
```json
"file_types": {
"C++": ["c"],
"TOML": ["MyLockFile"],
"Dockerfile": ["Dockerfile*"]
}
```
This configuration tells Zed to:
- Treat `.c` files as C++ instead of C
- Recognize files named "MyLockFile" as TOML
- Apply Dockerfile syntax to any file starting with "Dockerfile"
You can use glob patterns for more flexible matching, allowing you to handle complex naming conventions in your projects.
## Working with Language Servers
Language servers are a crucial part of Zed's intelligent coding features, providing capabilities like auto-completion, go-to-definition, and real-time error checking.
### What are Language Servers?
Language 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.
Some key features provided by language servers include:
- Code completion
- Error checking and diagnostics
- Code navigation (go to definition, find references)
- Code actions (Rename, extract method)
- Hover information
- Workspace symbol search
### Managing Language Servers
Zed simplifies language server management for users:
1. 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.
2. Storage Location:
- macOS: `~/Library/Application Support/Zed/languages`
- Linux: `$XDG_DATA_HOME/languages`, `$FLATPAK_XDG_DATA_HOME/languages`, or `$HOME/.local/share`
3. Automatic Updates: Zed keeps your language servers up-to-date, ensuring you always have the latest features and improvements.
### Choosing Language Servers
Some 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.
You can specify your preference using the `language_servers` setting:
```json
"languages": {
"PHP": {
"language_servers": ["intelephense", "!phpactor", "..."]
}
}
```
In this example:
- `intelephense` is set as the primary language server
- `phpactor` is disabled (note the `!` prefix)
- `...` expands to the rest of the language servers that are registered for PHP
This 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.
### Configuring Language Servers
Many language servers accept custom configuration options. You can set these in the `lsp` section of your `settings.json`:
```json
"lsp": {
"rust-analyzer": {
"initialization_options": {
"check": {
"command": "clippy"
}
}
}
}
```
This example configures the Rust Analyzer to use Clippy for additional linting when saving files.
#### Nested objects
When 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:
Suppose you want to configure the following settings for TypeScript:
- Enable strict null checks
- Set the target ECMAScript version to ES2020
Here's how you would structure these settings in Zed's `settings.json`:
```json
"lsp": {
"typescript-language-server": {
"initialization_options": {
// These are not supported (VSCode dotted style):
// "preferences.strictNullChecks": true,
// "preferences.target": "ES2020"
//
// These is correct (nested notation):