Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: explain how to get code completion to work when hacking on clippy #5514

Closed
matthiaskrgr opened this issue Apr 23, 2020 · 6 comments · Fixed by #5661
Closed

docs: explain how to get code completion to work when hacking on clippy #5514

matthiaskrgr opened this issue Apr 23, 2020 · 6 comments · Fixed by #5661
Labels
A-documentation Area: Adding or improving documentation C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. C-question Category: Questions S-needs-discussion Status: Needs further discussion before merging or work can be started

Comments

@matthiaskrgr
Copy link
Member

There have been several people in discord now asking how to get code-completion for rustc code when working on clippy code.

We should see if we can figure something out that works (using rust-analyzer?) and perhaps have some kind of guideline for getting it running for everyone, similar to the "how to get the rustc-master toolchain" section in the contribution guide. https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#fixing-build-failures-caused-by-rust

@matthiaskrgr matthiaskrgr added C-question Category: Questions S-needs-discussion Status: Needs further discussion before merging or work can be started A-documentation Area: Adding or improving documentation C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. labels Apr 23, 2020
@flip1995
Copy link
Member

flip1995 commented Apr 23, 2020

I hope, that this will be easier, once Clippy is a subtree in rustc and we can fix nightlies.

I have the most success with this setup (nvim + coc.nvim* + rust-analyzer):

Use master toolchain with -c rustc-dev (installed with setup-toolchain.sh) and -c rust-src + -c rustfmt (both not installed in setup-toolchain.sh)

+ errors are displayed for the latest rustc internals
image
+ code completion for Clippy internals
image
+ code completion for deps from Cargo.toml (not rustc-internals)
image
(color scheme is a bit broken, since this is a WSL instance in powershell...)

- no code completion for rustc internals
- no goto definition/... for rustc internals
- no auto format, when rustfmt is not available in master toolchain
- the rustfmt of the master toolchain may differ from the one used in CI (nightly)

*the coc.nvim plugin kind of emulates the LSP of vscode, so this should also work with vscode or other editors, that have a LSP implementation/plugin.

@matthiaskrgr
Copy link
Member Author

likely relevant: rust-lang/rust-analyzer#3517 (comment)

@tnielens
Copy link
Contributor

another one: intellij-rust/intellij-rust#1618

@matthiaskrgr
Copy link
Member Author

My current workaround is to redirect all the rustc dep paths to respective absolute paths to my rustc-repo. This blows up compiletime since I need to build 70% of rustc now but it makes rust-analyzer find rustc sources for analysis :)
You should also make sure that you have around 20-25 gigabyte of free space for the target dir.

diff --git a/Cargo.toml b/Cargo.toml
index 6999b6bd..027749c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,6 +35,11 @@ semver = "0.9"
 rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
 tempfile = { version = "3.1.0", optional = true }
 lazy_static = "1.0"
+# make rustc deps visible to rust analyzer
+rustc_driver = { path = "/home/matthias/vcs/github/rust/src/librustc_driver" }
+rustc_errors = { path = "/home/matthias/vcs/github/rust/src/librustc_errors" }
+rustc_interface = { path = "/home/matthias/vcs/github/rust/src/librustc_interface" }
+rustc_middle = { path = "/home/matthias/vcs/github/rust/src/librustc_middle" }

 [dev-dependencies]
 cargo_metadata = "0.9.0"
diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml
index 1c0be727..4f8b7e62 100644
--- a/clippy_lints/Cargo.toml
+++ b/clippy_lints/Cargo.toml
@@ -33,5 +33,28 @@ semver = "0.9.0"
 # see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
 url = { version =  "2.1.0", features = ["serde"] }

+# make rustc deps visible to rust analyzer
+fmt_macros = { path = "/home/matthias/vcs/github/rust/src/libfmt_macros" }
+rustc_ast = { path = "/home/matthias/vcs/github/rust/src/librustc_ast" }
+rustc_ast_pretty = { path = "/home/matthias/vcs/github/rust/src/librustc_ast_pretty" }
+rustc_attr = { path = "/home/matthias/vcs/github/rust/src/librustc_attr" }
+rustc_data_structures = { path = "/home/matthias/vcs/github/rust/src/librustc_data_structures" }
+rustc_driver = { path = "/home/matthias/vcs/github/rust/src/librustc_driver" }
+rustc_errors = { path = "/home/matthias/vcs/github/rust/src/librustc_errors" }
+rustc_hir = { path = "/home/matthias/vcs/github/rust/src/librustc_hir" }
+rustc_hir_pretty = { path = "/home/matthias/vcs/github/rust/src/librustc_hir_pretty" }
+rustc_index = { path = "/home/matthias/vcs/github/rust/src/librustc_index" }
+rustc_infer = { path = "/home/matthias/vcs/github/rust/src/librustc_infer" }
+rustc_lexer = { path = "/home/matthias/vcs/github/rust/src/librustc_lexer" }
+rustc_lint = { path = "/home/matthias/vcs/github/rust/src/librustc_lint" }
+rustc_middle = { path = "/home/matthias/vcs/github/rust/src/librustc_middle" }
+rustc_mir = { path = "/home/matthias/vcs/github/rust/src/librustc_mir" }
+rustc_parse = { path = "/home/matthias/vcs/github/rust/src/librustc_parse" }
+rustc_session = { path = "/home/matthias/vcs/github/rust/src/librustc_session" }
+rustc_span = { path = "/home/matthias/vcs/github/rust/src/librustc_span" }
+rustc_target = { path = "/home/matthias/vcs/github/rust/src/librustc_target" }
+rustc_trait_selection = { path = "/home/matthias/vcs/github/rust/src/librustc_trait_selection" }
+rustc_typeck = { path = "/home/matthias/vcs/github/rust/src/librustc_typeck" }
+
 [features]
 deny-warnings = []

ra_clippy

@tesuji
Copy link
Contributor

tesuji commented May 26, 2020

Why don't you use upstream libs?

@matthiaskrgr
Copy link
Member Author

Looks like there is no component that actually supplies the rustc source code (only libcore/liballoc/libstc etc)

matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 27, 2020
This crate takes am absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 27, 2020
This crate takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: ./souce_injector/target/debug/souce_injector /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 27, 2020
This crate takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: ./source_injector/target/debug/souce_injector /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 28, 2020
This takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: cargo dev ra-setup /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 28, 2020
This takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: cargo dev ra-setup /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 28, 2020
This takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: cargo dev ra-setup /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc rust-lang#5514
bors added a commit that referenced this issue May 28, 2020
cargo_dev: add ra_setup

It takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: cargo dev ra-setup /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc #5514

changelog: none
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 28, 2020
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 28, 2020
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 29, 2020
bors added a commit that referenced this issue May 31, 2020
cargo_dev: add ra-setup

It takes an absolute path to a rustc repo and adds path-dependencies
that point towards the respective rustc subcrates into the Cargo.tomls of
the clippy and clippy_lints crate.

This allows rustc-analyzer to show proper type annotations etc on rustc-internals inside the clippy repo.

Usage: cargo dev ra-setup /absolute/path/to/rust/

cc rust-lang/rust-analyzer#3517
cc #5514

changelog: none
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue May 31, 2020
bors added a commit that referenced this issue May 31, 2020
CONTRIBUTING: explain how to use cargo dev ra-setup

Fixes #5514

Technically this should be merged after #5655 but it's not very important.

---

changelog: none
bors added a commit that referenced this issue May 31, 2020
CONTRIBUTING: explain how to use cargo dev ra-setup

Fixes #5514

Technically this should be merged after #5655 but it's not very important.

---

changelog: none
@bors bors closed this as completed in 7727c4a May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. C-question Category: Questions S-needs-discussion Status: Needs further discussion before merging or work can be started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants