# rust-analyzer
Links: [[Rust]]
## General
[[macOS]]: https://rust-analyzer.github.io/manual.html#macos
[[Vim]] /[[Neovim]]: https://rust-analyzer.github.io/manual.html#vimneovim
### Install with [[Homebrew]]
```bash
brew install rust-analyzer
brew upgrade rust-analyzer
```
### Install with [[rustup]], or update after updating Rust toolchain
```bash
rust-analyzer --version # If updating
rustup component add rust-analyzer
rust-analyzer --version
```
### Get stdlib sources
https://rust-analyzer.github.io/manual.html#installation
```bash
rustup component add rust-src
```
## Config
### Prevent `#[cfg]` directives from showing warnings like this
![[Screen Shot 2022-07-05 at 7.11.18 PM.png]]
Set `rust-analyzer.diagnostics.disabled = "inactive-code"` - [source](https://users.rust-lang.org/t/can-i-stop-vscode-rust-analyzer-from-shading-out-cfgs/58773)
In [[Lua]], arrays are expressed as curly braces, and there is no `.` attribute syntax:
```lua
["rust-analyzer"] = {
diagnostics = {
-- Prevents cfg'd code from being all underlined as warning
disabled = {"inactive-code"},
},
}
```
## Debugging
### `failed to write request: Broken pipe (os error 32)`
![[signal-2022-06-27-185928_001.png]]
The problem may be related to proc macros and/or the rust version. [More info here](https://github.com/rust-lang/rust-analyzer/issues/10766).
[Debug steps](https://github.com/rust-lang/rust-analyzer/issues/10766#issuecomment-976362767) (some subset of which will be helpful)
- Bump your rust version to latest nightly
```bash
rustup update
```
If there is a `toolchain.toml`, make sure to update that too
- Check that `rust-analyzer` is using latest version of Rust
- Cargo clean
```bash
cargo clean
```
- Restart vim / reopen the offending file