docs: Update rust-analyzer docs (#17988)

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-09-18 10:04:02 +02:00 committed by GitHub
parent 2699fa8d4a
commit d4e10dfba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,37 +13,29 @@ TBD: Provide explicit examples not just `....`
## Inlay Hints ## Inlay Hints
The following configuration can be used to enable inlay hints for rust: The following configuration can be used to change the inlay hint settings for `rust-analyzer` in Rust:
```json ```json
{
"lsp": {
"rust-analyzer": {
"initialization_options": {
"inlayHints": { "inlayHints": {
"maxLength": null, "maxLength": null,
"lifetimeElisionHints": { "lifetimeElisionHints": {
"useParameterNames": true,
"enable": "skip_trivial" "enable": "skip_trivial"
"useParameterNames": true,
}, },
"closureReturnTypeHints": { "closureReturnTypeHints": {
"enable": "always" "enable": "always"
} }
} }
``` }
to make the language server send back inlay hints when Zed has them enabled in the settings.
Use
```json
"lsp": {
"rust-analyzer": {
"initialization_options": {
....
} }
} }
} }
``` ```
to override these settings.
See [Inlay Hints](https://rust-analyzer.github.io/manual.html#inlay-hints) in the Rust Analyzer Manual for more information. See [Inlay Hints](https://rust-analyzer.github.io/manual.html#inlay-hints) in the Rust Analyzer Manual for more information.
## Target directory ## Target directory
@ -70,7 +62,23 @@ A `true` setting will set the target directory to `target/rust-analyzer`. You ca
You can configure which `rust-analyzer` binary Zed should use. You can configure which `rust-analyzer` binary Zed should use.
To use a binary in a custom location, add the following to your `settings.json`: By default, Zed will try to find a `rust-analyzer` in your `$PATH` and try to use that. If that binary successfully executes `rust-analyzer --help`, it's used. Otherwise, Zed will fall back to installing its own `rust-analyzer` version and using that.
If you want to disable Zed looking for a `rust-analyzer` binary, you can set `path_lookup` to `false` in your `settings.json`:
```json
{
"lsp": {
"rust-analyzer": {
"binary": {
"path_lookup": false
}
}
}
}
```
If you want to use a binary in a custom location, you can specify a `path` and optional `args`:
```json ```json
{ {
@ -85,19 +93,7 @@ To use a binary in a custom location, add the following to your `settings.json`:
} }
``` ```
To use a binary that is on your `$PATH`, add the following to your `settings.json`: This `"path"` has to be an absolute path.
```json
{
"lsp": {
"rust-analyzer": {
"binary": {
"path_lookup": true
}
}
}
}
```
## More server configuration ## More server configuration
@ -138,7 +134,8 @@ Check on save feature is responsible for returning part of the diagnostics based
Consider more `rust-analyzer.cargo.` and `rust-analyzer.check.` and `rust-analyzer.diagnostics.` settings from the manual for more fine-grained configuration. Consider more `rust-analyzer.cargo.` and `rust-analyzer.check.` and `rust-analyzer.diagnostics.` settings from the manual for more fine-grained configuration.
Here's a snippet for Zed settings.json (the language server will restart automatically after the `lsp.rust-analyzer` section is edited and saved): Here's a snippet for Zed settings.json (the language server will restart automatically after the `lsp.rust-analyzer` section is edited and saved):
```json5 ```json
{
"lsp": { "lsp": {
"rust-analyzer": { "rust-analyzer": {
"initialization_options": { "initialization_options": {
@ -163,6 +160,7 @@ Here's a snippet for Zed settings.json (the language server will restart automat
} }
} }
} }
}
``` ```
### Snippets ### Snippets
@ -170,6 +168,7 @@ Here's a snippet for Zed settings.json (the language server will restart automat
There's a way get custom completion items from rust-analyzer, that will transform the code according to the snippet body: There's a way get custom completion items from rust-analyzer, that will transform the code according to the snippet body:
```json ```json
{
"lsp": { "lsp": {
"rust-analyzer": { "rust-analyzer": {
"initialization_options": { "initialization_options": {
@ -216,4 +215,5 @@ There's a way get custom completion items from rust-analyzer, that will transfor
} }
} }
} }
}
``` ```