Skip to content

Commit c5f3c60

Browse files
committed
Auto merge of rust-lang#3936 - YohDeadfall:rust-analyzer-conf, r=RalfJung
Added rust-analyzer instructions for Helix That pull request adds information on how to configure Helix to use `rust-analyzer`, and moves the existing configuration to the `src/etc` directory as it's in the `rust` repository. Not adding instructions for other IDE because there's a link leading to the how-to for `rustc`.
2 parents 58e0fba + 6f84740 commit c5f3c60

File tree

3 files changed

+87
-39
lines changed

3 files changed

+87
-39
lines changed

src/tools/miri/CONTRIBUTING.md

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -195,48 +195,37 @@ installed (`cargo install hyperfine`).
195195

196196
## Configuring `rust-analyzer`
197197

198-
To configure `rust-analyzer` and VS Code for working on Miri, save the following
199-
to `.vscode/settings.json` in your local Miri clone:
200-
201-
```json
202-
{
203-
"rust-analyzer.rustc.source": "discover",
204-
"rust-analyzer.linkedProjects": [
205-
"Cargo.toml",
206-
"cargo-miri/Cargo.toml",
207-
"miri-script/Cargo.toml",
208-
],
209-
"rust-analyzer.check.invocationLocation": "root",
210-
"rust-analyzer.check.invocationStrategy": "once",
211-
"rust-analyzer.check.overrideCommand": [
212-
"env",
213-
"MIRI_AUTO_OPS=no",
214-
"./miri",
215-
"clippy", // make this `check` when working with a locally built rustc
216-
"--message-format=json",
217-
],
218-
// Contrary to what the name suggests, this also affects proc macros.
219-
"rust-analyzer.cargo.buildScripts.invocationLocation": "root",
220-
"rust-analyzer.cargo.buildScripts.invocationStrategy": "once",
221-
"rust-analyzer.cargo.buildScripts.overrideCommand": [
222-
"env",
223-
"MIRI_AUTO_OPS=no",
224-
"./miri",
225-
"check",
226-
"--message-format=json",
227-
],
228-
}
229-
```
198+
To configure `rust-analyzer` and the IDE for working on Miri, copy one of the provided
199+
configuration files according to the instructions below. You can also set up a symbolic
200+
link to keep the configuration in sync with our recommendations.
201+
202+
### Visual Studio Code
203+
204+
Copy [`etc/rust_analyzer_vscode.json`] to `.vscode/settings.json` in the project root directory.
205+
206+
[`etc/rust_analyzer_vscode.json`]: https://github.com/rust-lang/miri/blob/master/etc/rust_analyzer_vscode.json
207+
208+
### Helix
209+
210+
Copy [`etc/rust_analyzer_helix.toml`] to `.helix/languages.toml` in the project root directory.
211+
212+
Since working on Miri requires a custom toolchain, and Helix requires the language server
213+
to be installed with the toolchain, you have to run `./miri toolchain -c rust-analyzer`
214+
when installing the Miri toolchain. Alternatively, set the `RUSTUP_TOOLCHAIN` environment variable according to
215+
[the documentation](https://rust-analyzer.github.io/manual.html#toolchain).
216+
217+
[`etc/rust_analyzer_helix.toml`]: https://github.com/rust-lang/miri/blob/master/etc/rust_analyzer_helix.toml
218+
219+
### Advanced configuration
230220

231-
> #### Note
232-
>
233-
> If you are [building Miri with a locally built rustc][], set
234-
> `rust-analyzer.rustcSource` to the relative path from your Miri clone to the
235-
> root `Cargo.toml` of the locally built rustc. For example, the path might look
236-
> like `../rust/Cargo.toml`.
221+
If you are building Miri with a locally built rustc, set
222+
`rust-analyzer.rustcSource` to the relative path from your Miri clone to the
223+
root `Cargo.toml` of the locally built rustc. For example, the path might look
224+
like `../rust/Cargo.toml`. In addition to that, replace `clippy` by `check`
225+
in the `rust-analyzer.check.overrideCommand` setting.
237226

238227
See the rustc-dev-guide's docs on ["Configuring `rust-analyzer` for `rustc`"][rdg-r-a]
239-
for more information about configuring VS Code and `rust-analyzer`.
228+
for more information about configuring the IDE and `rust-analyzer`.
240229

241230
[rdg-r-a]: https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc
242231

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[language-server.rust-analyzer.config.rustc]
2+
source = "discover"
3+
4+
[language-server.rust-analyzer.config]
5+
linkedProjects = [
6+
"Cargo.toml",
7+
"cargo-miri/Cargo.toml",
8+
"miri-script/Cargo.toml",
9+
]
10+
11+
[language-server.rust-analyzer.config.check]
12+
invocationLocation = "root"
13+
invocationStrategy = "once"
14+
overrideCommand = [
15+
"env",
16+
"MIRI_AUTO_OPS=no",
17+
"./miri",
18+
"clippy", # make this `check` when working with a locally built rustc
19+
"--message-format=json",
20+
]
21+
22+
# Contrary to what the name suggests, this also affects proc macros.
23+
[language-server.rust-analyzer.config.buildScripts]
24+
invocationLocation = "root"
25+
invocationStrategy = "once"
26+
overrideCommand = [
27+
"env",
28+
"MIRI_AUTO_OPS=no",
29+
"./miri",
30+
"check",
31+
"--message-format=json",
32+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"rust-analyzer.rustc.source": "discover",
3+
"rust-analyzer.linkedProjects": [
4+
"Cargo.toml",
5+
"cargo-miri/Cargo.toml",
6+
"miri-script/Cargo.toml",
7+
],
8+
"rust-analyzer.check.invocationLocation": "root",
9+
"rust-analyzer.check.invocationStrategy": "once",
10+
"rust-analyzer.check.overrideCommand": [
11+
"env",
12+
"MIRI_AUTO_OPS=no",
13+
"./miri",
14+
"clippy", // make this `check` when working with a locally built rustc
15+
"--message-format=json",
16+
],
17+
// Contrary to what the name suggests, this also affects proc macros.
18+
"rust-analyzer.cargo.buildScripts.invocationLocation": "root",
19+
"rust-analyzer.cargo.buildScripts.invocationStrategy": "once",
20+
"rust-analyzer.cargo.buildScripts.overrideCommand": [
21+
"env",
22+
"MIRI_AUTO_OPS=no",
23+
"./miri",
24+
"check",
25+
"--message-format=json",
26+
],
27+
}

0 commit comments

Comments
 (0)