Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions crates/rust-analyzer/src/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ pub(crate) enum Target {
}

impl CargoOptions {
pub(crate) fn apply_on_command(&self, cmd: &mut Command, ws_target_dir: Option<&Utf8Path>) {
pub(crate) fn apply_on_command(
&self,
cmd: &mut Command,
ws_target_dir: Option<&Utf8Path>,
package_repr: Option<&str>,
) {
for target in &self.target_tuples {
cmd.args(["--target", target.as_str()]);
}
Expand All @@ -83,8 +88,24 @@ impl CargoOptions {
cmd.arg("--no-default-features");
}
if !self.features.is_empty() {
// If we are scoped to a particular package, filter any features of the form
// `crate/feature` which target other packages.
let features = if let Some(name) = package_repr {
let filtered = self
.features
.iter()
.filter(|f| match f.split_once('/') {
Some((c, _)) => c == name,
None => true,
})
.map(|s| s.as_str())
.collect::<Vec<_>>();
filtered.join(" ")
} else {
self.features.join(" ")
};
cmd.arg("--features");
cmd.arg(self.features.join(" "));
cmd.arg(features);
}
}
if let Some(target_dir) = self.target_dir_config.target_dir(ws_target_dir) {
Expand Down Expand Up @@ -890,12 +911,18 @@ impl FlycheckActor {
cmd.env("CARGO_LOG", "cargo::core::compiler::fingerprint=info");
cmd.arg(&cargo_options.subcommand);

match scope {
FlycheckScope::Workspace => cmd.arg("--workspace"),
let package_repr = match scope {
FlycheckScope::Workspace => {
cmd.arg("--workspace");
None
}
FlycheckScope::Package {
package: PackageSpecifier::Cargo { package_id },
..
} => cmd.arg("-p").arg(&package_id.repr),
} => {
cmd.arg("-p").arg(&package_id.repr);
Some(package_id.repr.as_str())
}
FlycheckScope::Package {
package: PackageSpecifier::BuildInfo { .. }, ..
} => {
Expand Down Expand Up @@ -935,6 +962,7 @@ impl FlycheckActor {
cargo_options.apply_on_command(
&mut cmd,
self.ws_target_dir.as_ref().map(Utf8PathBuf::as_path),
package_repr,
);
cmd.args(&cargo_options.extra_args);
Some((cmd, FlycheckCommandOrigin::Cargo))
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl CargoTestHandle {
cmd.arg("--no-fail-fast");
cmd.arg("--manifest-path");
cmd.arg(root.join("Cargo.toml"));
options.apply_on_command(&mut cmd, ws_target_dir);
options.apply_on_command(&mut cmd, ws_target_dir, Some(&test_target.package));
cmd.arg("--");
if let Some(path) = path {
cmd.arg(path);
Expand Down
Loading