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
"inlayHints": { {
"maxLength": null, "lsp": {
"lifetimeElisionHints": { "rust-analyzer": {
"useParameterNames": true, "initialization_options": {
"enable": "skip_trivial" "inlayHints": {
}, "maxLength": null,
"closureReturnTypeHints": { "lifetimeElisionHints": {
"enable": "always" "enable": "skip_trivial"
} "useParameterNames": true,
} },
``` "closureReturnTypeHints": {
"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,30 +134,32 @@ 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": {
// get more cargo-less diagnostics from rust-analyzer, // get more cargo-less diagnostics from rust-analyzer,
// which might include false-positives (those can be turned off by their names) // which might include false-positives (those can be turned off by their names)
"diagnostics": { "diagnostics": {
"experimental": { "experimental": {
"enable": true "enable": true
} }
}, },
// To disable the checking entirely // To disable the checking entirely
// (ignores all cargo and check settings below) // (ignores all cargo and check settings below)
"checkOnSave": false, "checkOnSave": false,
// To check the `lib` target only. // To check the `lib` target only.
"cargo": { "cargo": {
"allTargets": false "allTargets": false
}, },
// Use `-p` instead of `--workspace` for cargo check // Use `-p` instead of `--workspace` for cargo check
"check": { "check": {
"workspace": false "workspace": false
}
} }
}
} }
}
} }
``` ```
@ -170,50 +168,52 @@ 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": {
"completion": { "completion": {
"snippets": { "snippets": {
"custom": { "custom": {
"Arc::new": { "Arc::new": {
"postfix": "arc", "postfix": "arc",
"body": ["Arc::new(${receiver})"], "body": ["Arc::new(${receiver})"],
"requires": "std::sync::Arc", "requires": "std::sync::Arc",
"scope": "expr" "scope": "expr"
}, },
"Some": { "Some": {
"postfix": "some", "postfix": "some",
"body": ["Some(${receiver})"], "body": ["Some(${receiver})"],
"scope": "expr" "scope": "expr"
}, },
"Ok": { "Ok": {
"postfix": "ok", "postfix": "ok",
"body": ["Ok(${receiver})"], "body": ["Ok(${receiver})"],
"scope": "expr" "scope": "expr"
}, },
"Rc::new": { "Rc::new": {
"postfix": "rc", "postfix": "rc",
"body": ["Rc::new(${receiver})"], "body": ["Rc::new(${receiver})"],
"requires": "std::rc::Rc", "requires": "std::rc::Rc",
"scope": "expr" "scope": "expr"
}, },
"Box::pin": { "Box::pin": {
"postfix": "boxpin", "postfix": "boxpin",
"body": ["Box::pin(${receiver})"], "body": ["Box::pin(${receiver})"],
"requires": "std::boxed::Box", "requires": "std::boxed::Box",
"scope": "expr" "scope": "expr"
}, },
"vec!": { "vec!": {
"postfix": "vec", "postfix": "vec",
"body": ["vec![${receiver}]"], "body": ["vec![${receiver}]"],
"description": "vec![]", "description": "vec![]",
"scope": "expr" "scope": "expr"
} }
}
}
} }
}
} }
}
} }
}
} }
``` ```