Find a file
bors[bot] a485c9b21d
Merge #7071
7071: Pass --all-targets to "cargo check" when discovering external resources r=matklad a=WasabiFan

There is a repro case and background in the linked issue.

In short, the goal of this MR is to allow rust-analyzer to discover proc-macros which come from your tests (including, most importantly, dev-dependencies).

By default, `cargo check` implies the equivalent of `--lib --bins`, meaning it'll check your libraries and binaries -- but not tests! This means proc-macros (or, I guess, build scripts as well) weren't discovered by rust-analyzer if they came from tests.

One solution would be to manually add `--lib --bins --tests` (i.e., just augment the effective options to include tests). However, in this MR, I threw in `--all-targets`, which [according to the docs](https://doc.rust-lang.org/cargo/commands/cargo-check.html#target-selection) implies `--benches --examples` too. I have absolutely no idea what repercussions that will have on rust-analyzer for other projects, nor do I know if it's a problem that build scripts will now be discovered for tests/examples/benches. But I am not aware of a reason you _wouldn't_ want to discover these things in your examples too.

I think the main drawback of this change is that it will likely slow down the `cargo check`. At a minimum, it'll now be checking your tests _and_ their dependencies. The `cargo check` docs also say that including `--tests` as I have here may cause your lib crate to be built _twice_, once for the normal target and again for unit tests. My reading of that caveat suggests that "building twice" means it's built once for the tests _inside_ your lib, with a test profile, and again for any consumers of your lib, now using a normal release profile or similar. This doesn't seem surprising.

Very minor caveat: `--tests`  will not include tests within a binary if it has `test = false` set in `Cargo.toml`. (I discovered this manually by trial-and-error, but hey, it actually says that in the docs!) This is likely not an issue, but _does_ mean that if you are -- for whatever reason -- disabling tests like that and then manually specifying `cargo test --package <...> --bin <...>` to run them, rust-analyzer will remain unaware of proc-macros in your tests.

I have confirmed this fixes the original issue in my sandbox example linked in #7034 and in my own project in which I originally discovered this. I've left it configured as my default RA language server and will report back if I notice any unexpected side-effects.

Fixes #7034


Co-authored-by: Kaelin Laundry <wasabifan@outlook.com>
2020-12-31 15:29:26 +00:00
.cargo Use lld on winsows 2020-08-19 20:17:49 +02:00
.github Set RA_TARGET at job level 2020-12-23 10:13:19 +02:00
.vscode vscode client side tests 2020-05-20 22:31:39 +03:00
assets Add SVG logos to assets directory 2020-08-28 21:41:45 +10:00
crates Merge #7071 2020-12-31 15:29:26 +00:00
docs Improve commit message style 2020-12-28 13:43:07 +03:00
editors/code Add an option for extra env vars in the Code extension 2020-12-30 04:51:07 -08:00
xtask Merge #7010 2020-12-23 10:37:30 +00:00
.gitattributes Rename ra_syntax -> syntax 2020-08-12 18:30:53 +02:00
.gitignore add open Cargo.toml action 2020-11-12 17:48:07 -08:00
bors.toml Reduce bors timeout 2020-10-14 13:37:20 +02:00
Cargo.lock Merge #7106 2020-12-31 15:11:14 +00:00
Cargo.toml Remove local ungrammar dependency 2020-12-23 11:22:36 +01:00
LICENSE-APACHE
LICENSE-MIT
PRIVACY.md Add notes concerning privacy and network access 2020-10-04 20:16:53 +03:00
README.md Replace logo in readme with SVG version 2020-08-28 21:42:12 +10:00
rustfmt.toml

rust-analyzer logo

rust-analyzer is an experimental modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.

Work on rust-analyzer is sponsored by

Ferrous Systems

Quick Start

https://rust-analyzer.github.io/manual.html#installation

Documentation

If you want to contribute to rust-analyzer or are just curious about how things work under the hood, check the ./docs/dev folder.

If you want to use rust-analyzer's language server with your editor of choice, check the manual folder. It also contains some tips & tricks to help you be more productive when using rust-analyzer.

Communication

For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum:

https://users.rust-lang.org/c/ide/14

For questions about development and implementation, join rls-2.0 working group on Zulip:

https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0

License

Rust analyzer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.