Skip to content

Commit a2ee849

Browse files
committed
Auto merge of rust-lang#6888 - matthiaskrgr:rip_ra_setup, r=flip1995
docs: update RA setup documentation Add documentation how to get rust-analyzer to like clippys `extern crate` rustc deps. Fixes rust-lang#6883 This initially removed `cargo-dev ra_setup` but it is still needed by folks who use intellij rust, so keeping that. changelog: none
2 parents 56161b2 + 6546285 commit a2ee849

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

CONTRIBUTING.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ All contributors are expected to follow the [Rust Code of Conduct].
1818
- [Finding something to fix/improve](#finding-something-to-fiximprove)
1919
- [Writing code](#writing-code)
2020
- [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work)
21+
- [IntelliJ Rust](#intellij-rust)
22+
- [Rust Analyzer](#rust-analyzer)
2123
- [How Clippy works](#how-clippy-works)
22-
- [Syncing changes between Clippy and `rust-lang/rust`](#syncing-changes-between-clippy-and-rust-langrust)
24+
- [Syncing changes between Clippy and [`rust-lang/rust`]](#syncing-changes-between-clippy-and-rust-langrust)
2325
- [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos)
24-
- [Performing the sync from `rust-lang/rust` to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
25-
- [Performing the sync from Clippy to `rust-lang/rust`](#performing-the-sync-from-clippy-to-rust-langrust)
26+
- [Performing the sync from [`rust-lang/rust`] to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
27+
- [Performing the sync from Clippy to [`rust-lang/rust`]](#performing-the-sync-from-clippy-to-rust-langrust)
2628
- [Defining remotes](#defining-remotes)
2729
- [Issue and PR triage](#issue-and-pr-triage)
2830
- [Bors and Homu](#bors-and-homu)
@@ -105,21 +107,41 @@ quick read.
105107

106108
## Getting code-completion for rustc internals to work
107109

108-
Unfortunately, [`rust-analyzer`][ra_homepage] does not (yet?) understand how Clippy uses compiler-internals
110+
### IntelliJ Rust
111+
Unfortunately, [`IntelliJ Rust`][IntelliJ_rust_homepage] does not (yet?) understand how Clippy uses compiler-internals
109112
using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not
110113
available via a `rustup` component at the time of writing.
111114
To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via
112115
`git clone https://github.com/rust-lang/rust/`.
113116
Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies
114-
which rust-analyzer will be able to understand.
115-
Run `cargo dev ra_setup --repo-path <repo-path>` where `<repo-path>` is an absolute path to the rustc repo
117+
which `IntelliJ Rust` will be able to understand.
118+
Run `cargo dev ide_setup --repo-path <repo-path>` where `<repo-path>` is a path to the rustc repo
116119
you just cloned.
117120
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
118121
Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses.
119122
Just make sure to remove the dependencies again before finally making a pull request!
120123

121-
[ra_homepage]: https://rust-analyzer.github.io/
122124
[rustc_repo]: https://github.com/rust-lang/rust/
125+
[IntelliJ_rust_homepage]: https://intellij-rust.github.io/
126+
127+
### Rust Analyzer
128+
As of [#6869][6869], [`rust-analyzer`][ra_homepage] can understand that Clippy uses compiler-internals
129+
using `extern crate` when `package.metadata.rust-analyzer.rustc_private` is set to `true` in Clippys `Cargo.toml.`
130+
You will required a `nightly` toolchain with the `rustc-dev` component installed.
131+
Make sure that in the `rust-analyzer` configuration, you set
132+
```
133+
{ "rust-analyzer.rustcSource": "discover" }
134+
```
135+
and
136+
```
137+
{ "rust-analyzer.updates.channel": "nightly" }
138+
```
139+
You should be able to see information on things like `Expr` or `EarlyContext` now if you hover them, also
140+
a lot more type hints.
141+
This will work with `rust-analyzer 2021-03-15` shipped in nightly `1.52.0-nightly (107896c32 2021-03-15)` or later.
142+
143+
[ra_homepage]: https://rust-analyzer.github.io/
144+
[6869]: https://github.com/rust-lang/rust-clippy/pull/6869
123145

124146
## How Clippy works
125147

clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn run(check: bool, verbose: bool) {
9090
},
9191
CliError::RaSetupActive => {
9292
eprintln!(
93-
"error: a local rustc repo is enabled as path dependency via `cargo dev ra_setup`.
93+
"error: a local rustc repo is enabled as path dependency via `cargo dev ide_setup`.
9494
Not formatting because that would format the local repo as well!
9595
Please revert the changes to Cargo.tomls first."
9696
);

clippy_dev/src/ra_setup.rs renamed to clippy_dev/src/ide_setup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn inject_deps_into_manifest(
5555
// do not inject deps if we have aleady done so
5656
if cargo_toml.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") {
5757
eprintln!(
58-
"cargo dev ra_setup: warning: deps already found inside {}, doing nothing.",
58+
"cargo dev ide_setup: warning: deps already found inside {}, doing nothing.",
5959
manifest_path
6060
);
6161
return Ok(());

clippy_dev/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use walkdir::WalkDir;
1212

1313
pub mod bless;
1414
pub mod fmt;
15+
pub mod ide_setup;
1516
pub mod new_lint;
16-
pub mod ra_setup;
1717
pub mod serve;
1818
pub mod stderr_length_check;
1919
pub mod update_lints;

clippy_dev/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

33
use clap::{App, Arg, ArgMatches, SubCommand};
4-
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
4+
use clippy_dev::{bless, fmt, ide_setup, new_lint, serve, stderr_length_check, update_lints};
55
fn main() {
66
let matches = get_clap_config();
77

@@ -34,7 +34,7 @@ fn main() {
3434
("limit_stderr_length", _) => {
3535
stderr_length_check::check();
3636
},
37-
("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
37+
("ide_setup", Some(matches)) => ide_setup::run(matches.value_of("rustc-repo-path")),
3838
("serve", Some(matches)) => {
3939
let port = matches.value_of("port").unwrap().parse().unwrap();
4040
let lint = matches.value_of("lint");
@@ -138,8 +138,8 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
138138
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
139139
)
140140
.subcommand(
141-
SubCommand::with_name("ra_setup")
142-
.about("Alter dependencies so rust-analyzer can find rustc internals")
141+
SubCommand::with_name("ide_setup")
142+
.about("Alter dependencies so Intellij Rust can find rustc internals")
143143
.arg(
144144
Arg::with_name("rustc-repo-path")
145145
.long("repo-path")

doc/basics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ cargo dev fmt
8888
cargo dev update_lints
8989
# create a new lint and register it
9090
cargo dev new_lint
91-
# (experimental) Setup Clippy to work with rust-analyzer
92-
cargo dev ra_setup
91+
# (experimental) Setup Clippy to work with IntelliJ-Rust
92+
cargo dev ide_setup
9393
```
9494

9595
## lintcheck

0 commit comments

Comments
 (0)