You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
apply_on_command adds --all-targets if the config value all_targets is true (which is the default).
Sadly, Cargo currently ignores any target specification like --bin BIN_NAME if --all-targets is specified. Which means that PR #17912 is ineffective right now.
So what is the solution? Don't pass --all-targets when a specific target is passed? This currently can't be the solution.
The first problem is that when not using --all-targets and without --profile test, Cargo doesn't check tests with #[cfg(test)]. So we should (always?) add --profile test to cargo check?
The second problem is that Rust-Analyzer seems to forget all errors and warnings after an invocation of cargo check. See the video from VS-Code in a Windows VM with the pre-release Rust-Analyzer extension:
Screencast.from.2024-09-13.15-47-18.webm
In this video, I disabled all_targets in the extension settings. When Rust-Analyzer starts, it runs cargo check and collects 113 errors and 8 warnings. Then, while still starting up, it forgets all these errors and warnings and runs cargo check again until it reaches the same 113 errors and 8 warnings that it already had!?
But this isn't the main issue here. The issue is that, after saving one file associated with a binary, Rust-Analyzer runs cargo check --bin if1 quickly as expected from #17912 but it forgets all diagnostics it had before about the other targets!
TL;DR
We need to omit --all-targets when specifying a specific target like --bin.
We need to pass --target test to the check command.
Rust-Analyzer shouldn't forget all diagnostics from other targets.
(Why does Rust-Analyzer run cargo check twice on startup?)
We apply a target in this line:
rust-analyzer/crates/rust-analyzer/src/flycheck.rs
Line 411 in 4221354
But then,
apply_on_command
is called in this line:rust-analyzer/crates/rust-analyzer/src/flycheck.rs
Line 435 in 4221354
apply_on_command
adds--all-targets
if the config valueall_targets
is true (which is the default).Sadly, Cargo currently ignores any target specification like
--bin BIN_NAME
if--all-targets
is specified. Which means that PR #17912 is ineffective right now.So what is the solution? Don't pass
--all-targets
when a specific target is passed? This currently can't be the solution.The first problem is that when not using
--all-targets
and without--profile test
, Cargo doesn't check tests with#[cfg(test)]
. So we should (always?) add--profile test
tocargo check
?The second problem is that Rust-Analyzer seems to forget all errors and warnings after an invocation of
cargo check
. See the video from VS-Code in a Windows VM with the pre-release Rust-Analyzer extension:Screencast.from.2024-09-13.15-47-18.webm
In this video, I disabled
all_targets
in the extension settings. When Rust-Analyzer starts, it runscargo check
and collects 113 errors and 8 warnings. Then, while still starting up, it forgets all these errors and warnings and runscargo check
again until it reaches the same 113 errors and 8 warnings that it already had!?But this isn't the main issue here. The issue is that, after saving one file associated with a binary, Rust-Analyzer runs
cargo check --bin if1
quickly as expected from #17912 but it forgets all diagnostics it had before about the other targets!TL;DR
--all-targets
when specifying a specific target like--bin
.--target test
to the check command.cargo check
twice on startup?)CC @alibektas @Veykril from the other PR.
The text was updated successfully, but these errors were encountered: