Add more documentation about ways to configure language servers and rust-analyzer (#29932)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-05-05 19:10:10 +03:00 committed by GitHub
parent c56a1cf2b1
commit 76c0eded0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 91 additions and 1 deletions

View file

@ -297,7 +297,7 @@ pub struct BinarySettings {
pub path: Option<String>,
pub arguments: Option<Vec<String>>,
// this can't be an FxHashMap because the extension APIs require the default SipHash
pub env: Option<std::collections::HashMap<String, String, std::hash::RandomState>>,
pub env: Option<std::collections::HashMap<String, String>>,
pub ignore_system_version: Option<bool>,
}

View file

@ -182,6 +182,63 @@ Here's how you would structure these settings in Zed's `settings.json`:
}
```
#### Possible configuration options
Depending on how a particular language server is implemented, they may depend on different configuration options, both specified in the LSP.
- [initializationOptions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#version_3_17_0)
Sent once during language server startup, requires server's restart to reapply changes.
For example, rust-analyzer and clangd rely on this way of configuring only.
```json
"lsp": {
"rust-analyzer": {
"initialization_options": {
"checkOnSave": false
}
}
}
```
- [Configuration Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)
May be queried by the server multiple times.
Most of the servers would rely on this way of configuring only.
```json
"lsp": {
"tailwindcss-language-server": {
"settings": {
"tailwindCSS": {
"emmetCompletions": true,
},
}
}
}
```
Apart of the LSP-related server configuration options, certain servers in Zed allow configuring the way binary is launched by Zed.
Languages mention in the documentation, whether they support it or not and their defaults for the configuration values:
```json
"languages": {
"Markdown": {
"binary": {
// Whether to fetch the binary from the internet, or attempt to find locally.
"ignore_system_version": false,
"path": "/path/to/langserver/bin",
"arguments": ["--option", "value"],
"env": {
"FOO": "BAR"
}
}
}
}
```
### Enabling or Disabling Language Servers
You can toggle language server support globally or per-language:

View file

@ -119,6 +119,39 @@ If you are using `rustup` and you can find a list of available target triples (`
rustup target list --installed
```
## LSP tasks
Zed provides tasks using tree-sitter, but rust-analyzer has an LSP extension method for querying file-related tasks via LSP.
This is enabled by default and can be configured as
```json
"lsp": {
"rust-analyzer": {
enable_lsp_tasks": true,
}
}
```
## Manual Cargo Diagnostics fetch
By default, rust-analyzer has `checkOnSave: true` enabled, which causes every buffer save to trigger a `cargo check --workspace --all-targets` command.
For lager projects this might introduce excessive wait times, so a more fine-grained triggering could be enabled by altering the
```json
"diagnostics": {
"cargo": {
// When enabled, Zed disables rust-analyzer's check on save and starts to query
// Cargo diagnostics separately.
"fetch_cargo_diagnostics": false
}
}
```
default settings.
This will stop rust-analyzer from running `cargo check ...` on save, yet still allow to run
`editor: run/clear/cancel flycheck` commands in Rust files to refresh cargo diagnostics; the project diagnostics editor will also refresh cargo diagnostics with `editor: run flycheck` command when the setting is enabled.
## More server configuration
<!--