Commit Graph

105 Commits

Author SHA1 Message Date
Aleksey Kladov
188b0f96f9 Add more docs 2021-05-22 16:53:47 +03:00
Brendan Cully
c4664609ed Use package root as cargo check working directory
Cargo commands are affected by the `.cargo/config` files above
their working directory. If cargo is invoked from above the directory
holding `Cargo.toml`, it may not pick up important settings like
registry replacements, causing it to behave differently or even fail.

Most cargo invocations are currently setting their working directories
to the directory containing `Cargo.toml`, but a couple of paths remain
in which cargo is invoked from the default workspace root instead.

This change fixes that, resolving some cargo check failures that I
experienced in a multi-root workspace in which packages used different
registries.
2021-05-12 19:50:52 -07:00
Jonas Schievink
a272cdfecd Fix build script dependencies 2021-05-12 14:48:26 +02:00
Jonas Schievink
32560839d9 Use Cargo target name as crate name 2021-05-11 23:34:56 +02:00
Lukas Wirth
b7e6537935 Use RUSTC_BOOTSTRAP=1 instead of +nightly when discovering rust_cfgs throughs cargo 2021-05-09 00:07:04 +02:00
Lukas Wirth
8989fb8315 Discover rustc_cfg through unstable cargo options 2021-05-08 18:17:18 +02:00
Aleksey Kladov
6a16ec52aa internal: use API stabilized in 1.52 2021-05-06 20:12:15 +03:00
Aleksey Kladov
363cef5c0e fix: make error message in the status bar more useful
At the moment,the popup is just a bazillion of Cargo's "Compiling this\nCompiling that",
which is not that useful.

--quiet still displays error, which is what we needc
2021-04-26 19:16:07 +03:00
Aleksey Kladov
1772eb0f1a fix: no longer get stuck on windows
reading both stdout & stderr is a common gotcha, you need to drain them
concurrently to avoid deadlocks. Not sure why I didn't do the right
thing from the start. Seems like I assumed the stderr is short? That's
not the case when cargo spams `compiling xyz` messages
2021-04-20 18:02:54 +03:00
Aleksey Kladov
186c5c47cb feat: avoid checking the whole project during initial loading 2021-04-12 15:29:31 +03:00
Aleksey Kladov
de33702784 feat: show errors from cargo metadata and initial cargo check in the status bar
closes #3155
2021-04-06 18:08:05 +03:00
Aleksey Kladov
9ec5e6e4fd Clearer naming 2021-04-06 16:22:26 +03:00
Aleksey Kladov
aaa8c208b1 internal: do not drop errors from cargo metadata/check
Work towards #3155
2021-04-06 12:33:19 +03:00
Matthias Krüger
ae7e55c1dd clippy::complexity simplifications related to Iterators 2021-03-21 13:13:34 +01:00
Matthias Krüger
cad617bba0 some clippy::performance fixes
use vec![] instead of Vec::new() +  push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unneccessary resizing
2021-03-15 10:19:59 +01:00
Daniel McNab
d0a51d710e Never run cargo check on the rustc source 2021-03-08 16:42:18 +00:00
Daniel McNab
d5d406fa78 Only show directory name 2021-03-08 16:41:40 +00:00
Daniel McNab
bbecea03fd Revert "Support disabling rustc build scripts"
This reverts commit ddce6bb282.
2021-03-08 16:37:52 +00:00
Daniel McNab
ddce6bb282 Support disabling rustc build scripts 2021-03-08 09:05:19 +00:00
Daniel McNab
877f745551 Fix the comment
It's worse than I thought...
2021-03-07 13:13:54 +00:00
Daniel McNab
419b5a1bee Extract the large nested block into a function
Also add some more detailed comments
Extract into function deleted the previous comments
2021-03-07 12:59:15 +00:00
Daniel McNab
9246df669a Require opt in to rustc_private
This gives the advantage that

A future extension would be to check for `feature(rustc_private)` instead
2021-03-07 12:24:20 +00:00
Daniel McNab
71a254c1a1 Don't double analyse the same crate 2021-03-07 11:17:14 +00:00
Daniel McNab
b46605cfcd Update crate graph to only use subcrates of rustc_driver 2021-03-07 10:18:01 +00:00
Daniel McNab
7513867aa2 If a manual dependency exists, don't overwrite
This is a hack to work around miri being included in
our analysis of rustc-dev
Really, we should probably use an include set of the actual root libraries

I'm not sure how those are determined however
2021-03-06 13:56:42 +00:00
Daniel McNab
1076d21fc0 Implement opt-in (and opt-out) rustc_private 2021-03-06 12:17:22 +00:00
Laurențiu Nicola
b20708f6ee Bump cargo_metadata 2021-03-02 14:27:29 +02:00
kjeremy
f9bb398cc5 Fix a few clippy::perf warnings 2021-02-16 10:55:34 -05:00
Benjamin Bouvier
4a6e602c94 Allow automatically detect the rustc-src directory (fixes #3517).
If the configured rustcSource is set to "discover", try to automatically
detect a source from the sysroot rustc directory.
2021-02-13 18:20:46 +01:00
Edwin Cheng
9358eecc04 Async Loading outdir and proc-macro 2021-01-29 01:04:14 +08:00
Aleksey Kladov
4b59c3a538 Make logger-based debugging more pleasant 2021-01-28 17:07:53 +03:00
Jonas Schievink
481a74eda7 Export CARGO for proc. macros 2021-01-27 14:25:51 +01:00
Edwin Cheng
eb2cb6b01f Use AbsPath 2021-01-22 19:51:14 +08:00
Edwin Cheng
6bdb6786ba Refactor build script data 2021-01-22 19:11:01 +08:00
Edwin Cheng
ac3ec18f4b Added defined_features in PackageData 2021-01-21 19:12:19 +08:00
Aleksey Kladov
add87f5424 Avoid blocking the main loop when editing Cargo.toml
I've noticed a bunch of "main loop too long" warnings in console when
typing in Cargo.toml. Profiling showed that the culprit is `rustc
--print cfg` call.

I moved it to the background project loading phase, where it belongs.
This highlighted a problem: we generally use single `cfg`, while it
really should be per crate.
2021-01-18 14:52:12 +03:00
Aleksey Kladov
cc963d2b11 Add profile call 2021-01-18 14:01:52 +03:00
Aleksey Kladov
e13065b8ac Add profile call 2021-01-18 13:30:12 +03:00
Aleksey Kladov
1c8feac01f ⬆️ arena 2021-01-17 11:43:04 +03:00
Aramis Razzaghipour
709034d123
Depend on local copy of la-arena instead of crates.io’s 2021-01-17 17:52:57 +11:00
Aleksey Kladov
4c4e54ac8a prepare to publish el libro de arena 2021-01-14 19:06:02 +03:00
Chinedu Francis Nwafili
47c5ec4b94
Use --workspace when loading extern resources
https://github.com/rust-analyzer/rust-analyzer/issues/5040#issuecomment-759853153
2021-01-14 06:03:41 -05:00
kjeremy
1da68e87af Unfreeze cargo_metadata
It now pulls in a newer version of semver-parser.
2021-01-11 08:27:16 -05:00
Edwin Cheng
2b2d699b35 Report progress for cargo metadata and output-dir 2021-01-08 01:18:58 +08:00
Arnaud
ef636ba346 Document project_model::TargetData
This adds a description for `TargetData` and all its fields.
2021-01-06 17:26:21 +01:00
Arnaud
0abe487f1c Document project_model::PackageData
This adds a description for `PackageData` and all its fields.
2021-01-06 17:26:15 +01:00
Arnaud
7c3e163e90 Make PackageData, TargetData and PackageDependency public
This makes them discoverable through documentation.
They were already publicly accessible through `Package` and `Target`.
2021-01-06 16:33:29 +01:00
Aleksey Kladov
f7a15b5cd1 More maintainable config
Rather than eagerly converting JSON, we losslessly keep it as is, and
change the shape of user-submitted data at the last moment.

This also allows us to remove a bunch of wrong Defaults
2021-01-06 15:39:28 +03:00
Mara Bos
4833972067 Add support for Rust 2021. 2021-01-01 17:22:23 +01:00
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