Skip to content

Commit 92befb7

Browse files
committed
Add Neovim configuration information
The JSON provided for VSCode works with coc and nlsp-settings. This is verified by https://github.com/fannheyward/coc-rust-analyzer/blob/9d8bdb9290e2a9644367594a1ceed0288506efcd/README.md for coc, and feeding the JSON in to this schema https://github.com/tamago324/nlsp-settings.nvim/blob/215b537cfb3fad7c9c2e352fe47a10698b0993e0/schemas/_generated/rust_analyzer.json for validating nlsp-settings. The Lua translation is straight-forward and is how all rust-analyzer settings must be used with native nvim lsp.
1 parent df5aee0 commit 92befb7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/building/suggested.md

+38
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,44 @@ you to create a `.vscode/settings.json` file which will configure Visual Studio
2727
This will ask `rust-analyzer` to use `./x.py check` to check the sources, and the
2828
stage 0 rustfmt to format them.
2929

30+
31+
For Neovim users there are several options for configuring for rustc. You can use the native LSP server and make your own logic for changing the rust-analyzer configuration to the above. You can also use [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local configuration files. This plugin allows for the above JSON to be directly put in to a file located at `rust/.nlsp-settings/rust_analyzer.json`. If you use [coc-rust-analyzer](https://github.com/fannheyward/coc-rust-analyzer) you can also use the above JSON, but placed in `rust/.vim/coc-settings.json`.
32+
33+
Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode configuration
34+
35+
```lua
36+
{
37+
["rust-analyzer"] = {
38+
checkOnSave = {
39+
overrideCommand = {
40+
{"python3", "x.py", "check", "--json-output"}
41+
}
42+
},
43+
rustfmt = {
44+
overrideCommand = {
45+
{"./build/host/stage0/bin/rustfmt", "--edition=2021"}
46+
}
47+
},
48+
procMacro = {
49+
server = "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",
50+
enable = true
51+
},
52+
cargo = {
53+
buildScripts = {
54+
enable = true,
55+
invocationLocation = "root",
56+
invocationStrategy = "once",
57+
overrideCommand = {"python3", "x.py", "check", "--json-output"}
58+
},
59+
sysroot = "./build/host/stage0-sysroot"
60+
},
61+
rustc = {
62+
source = "./Cargo.toml"
63+
}
64+
}
65+
}
66+
```
67+
3068
If you have enough free disk space and you would like to be able to run `x.py` commands while
3169
rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the
3270
`overrideCommand` to avoid x.py locking.

0 commit comments

Comments
 (0)