Skip to content

Commit ee3c3a8

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 da0a4a0 commit ee3c3a8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/building/suggested.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,44 @@ you can write: <!-- date-check: nov 2022 --><!-- the date comment is for the edi
5656
in your `.vscode/settings.json` file. This will ask `rust-analyzer` to use
5757
`./x.py check` to check the sources, and the stage 0 rustfmt to format them.
5858

59+
60+
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`.
61+
62+
Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode configuration
63+
64+
```lua
65+
{
66+
["rust-analyzer"] = {
67+
checkOnSave = {
68+
overrideCommand = {
69+
{"python3", "x.py", "check", "--json-output"}
70+
}
71+
},
72+
rustfmt = {
73+
overrideCommand = {
74+
{"./build/host/stage0/bin/rustfmt", "--edition=2021"}
75+
}
76+
},
77+
procMacro = {
78+
server = "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",
79+
enable = true
80+
},
81+
cargo = {
82+
buildScripts = {
83+
enable = true,
84+
invocationLocation = "root",
85+
invocationStrategy = "once",
86+
overrideCommand = {"python3", "x.py", "check", "--json-output"}
87+
},
88+
sysroot = "./build/host/stage0-sysroot"
89+
},
90+
rustc = {
91+
source = "./Cargo.toml"
92+
}
93+
}
94+
}
95+
```
96+
5997
If you have enough free disk space and you would like to be able to run `x.py` commands while
6098
rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the
6199
`overrideCommand` to avoid x.py locking.

0 commit comments

Comments
 (0)