Skip to content

Commit 61a8154

Browse files
committed
Rebase and update with seperate sections for VSCode and Nvim
1 parent 4431c3d commit 61a8154

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

Diff for: src/building/suggested.md

+40-38
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ You can also install the hook as a step of running `./x.py setup`!
1919

2020
## Configuring `rust-analyzer` for `rustc`
2121

22+
### Visual Studio Code
23+
2224
`rust-analyzer` can help you check and format your code whenever you save
2325
a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt`
2426
commands, but you can override these commands to use more adapted versions
@@ -27,20 +29,49 @@ you to create a `.vscode/settings.json` file which will configure Visual Studio
2729
This will ask `rust-analyzer` to use `./x.py check` to check the sources, and the
2830
stage 0 rustfmt to format them.
2931

32+
If you have enough free disk space and you would like to be able to run `x.py` commands while
33+
rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the
34+
`overrideCommand` to avoid x.py locking.
3035

31-
For Neovim users there are several options for configuring for rustc. The easiest way is by using
32-
[nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local
33-
configuration files with the native LSP. The steps for how to use it are below.
36+
If running `./x.py check` on save is inconvenient, in VS Code you can use a [Build
37+
Task] instead:
3438

35-
1. First install the plugin
36-
2. Run `:LspSettings local rust_analyzer` while the rust repo is open.
39+
```JSON
40+
// .vscode/tasks.json
41+
{
42+
"version": "2.0.0",
43+
"tasks": [
44+
{
45+
"label": "./x.py check",
46+
"command": "./x.py check",
47+
"type": "shell",
48+
"problemMatcher": "$rustc",
49+
"presentation": { "clear": true },
50+
"group": { "kind": "build", "isDefault": true }
51+
}
52+
]
53+
}
54+
```
55+
56+
[Build Task]: https://code.visualstudio.com/docs/editor/tasks
3757

38-
This will create and open a JSON file to put the above JSON in.
3958

40-
3. Open a Rust buffer that causes Rust Analyzer to attach.
41-
4. Run `:LspSettings update rust_analyzer`
59+
### Neovim
4260

43-
The final step must be repeated every time you open Neovim after you open a Rust buffer.
61+
For Neovim users there are several options for configuring for rustc. The easiest way is by using
62+
[neoconf.nvim](https://github.com/folke/neoconf.nvim/), which allows for project-local
63+
configuration files with the native LSP. The steps for how to use it are below. Note that requires
64+
Rust-Analyzer to already be configured with Neovim. Steps for this can be
65+
[found here](https://rust-analyzer.github.io/manual.html#nvim-lsp).
66+
67+
1. First install the plugin. This can be done by following the steps in the README.
68+
2. Run `x.py setup`, which will have a prompt for it to create a `.vscode/settings.json` file. `neoconf`
69+
is able to read and update Rust-Analyzer settings automatically when the project is opened when this
70+
file is detected.
71+
72+
If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a
73+
`.vim/coc-settings.json` and copy the settings from
74+
[this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json).
4475

4576
Another way is without a plugin, and creating your own logic in your configuration. The required
4677
Lua for doing so is below.
@@ -78,35 +109,6 @@ Lua for doing so is below.
78109
}
79110
```
80111

81-
If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a
82-
`.vim/coc-settings.json` and copy the settings from [this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json).
83-
84-
If you have enough free disk space and you would like to be able to run `x.py` commands while
85-
rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the
86-
`overrideCommand` to avoid x.py locking.
87-
88-
If running `./x.py check` on save is inconvenient, in VS Code you can use a [Build
89-
Task] instead:
90-
91-
```JSON
92-
// .vscode/tasks.json
93-
{
94-
"version": "2.0.0",
95-
"tasks": [
96-
{
97-
"label": "./x.py check",
98-
"command": "./x.py check",
99-
"type": "shell",
100-
"problemMatcher": "$rustc",
101-
"presentation": { "clear": true },
102-
"group": { "kind": "build", "isDefault": true }
103-
}
104-
]
105-
}
106-
```
107-
108-
[Build Task]: https://code.visualstudio.com/docs/editor/tasks
109-
110112
## Check, check, and check again
111113

112114
When doing simple refactorings, it can be useful to run `./x.py check`

0 commit comments

Comments
 (0)