5596: Add checkOnSave.noDefaultFeatures and correct, how we handle some cargo flags. r=clemenswasser a=clemenswasser

This PR adds the `rust-analyzer.checkOnSave.noDefaultFeatures` option
and fixes the handling of `cargo.allFeatures`, `cargo.noDefaultFeatures` and `cargo.features`.
Fixes: #5550 

Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
This commit is contained in:
bors[bot] 2020-07-30 21:23:41 +00:00 committed by GitHub
commit 6b7cb8b5ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 14 deletions

View file

@ -24,6 +24,7 @@ pub enum FlycheckConfig {
command: String, command: String,
target_triple: Option<String>, target_triple: Option<String>,
all_targets: bool, all_targets: bool,
no_default_features: bool,
all_features: bool, all_features: bool,
features: Vec<String>, features: Vec<String>,
extra_args: Vec<String>, extra_args: Vec<String>,
@ -180,6 +181,7 @@ impl FlycheckActor {
FlycheckConfig::CargoCommand { FlycheckConfig::CargoCommand {
command, command,
target_triple, target_triple,
no_default_features,
all_targets, all_targets,
all_features, all_features,
extra_args, extra_args,
@ -198,9 +200,14 @@ impl FlycheckActor {
} }
if *all_features { if *all_features {
cmd.arg("--all-features"); cmd.arg("--all-features");
} else if !features.is_empty() { } else {
cmd.arg("--features"); if *no_default_features {
cmd.arg(features.join(" ")); cmd.arg("--no-default-features");
}
if !features.is_empty() {
cmd.arg("--features");
cmd.arg(features.join(" "));
}
} }
cmd.args(extra_args); cmd.args(extra_args);
cmd cmd

View file

@ -144,12 +144,15 @@ impl CargoWorkspace {
meta.manifest_path(cargo_toml.to_path_buf()); meta.manifest_path(cargo_toml.to_path_buf());
if cargo_features.all_features { if cargo_features.all_features {
meta.features(CargoOpt::AllFeatures); meta.features(CargoOpt::AllFeatures);
} else if cargo_features.no_default_features { } else {
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` if cargo_features.no_default_features {
// https://github.com/oli-obk/cargo_metadata/issues/79 // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
meta.features(CargoOpt::NoDefaultFeatures); // https://github.com/oli-obk/cargo_metadata/issues/79
} else if !cargo_features.features.is_empty() { meta.features(CargoOpt::NoDefaultFeatures);
meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); }
if !cargo_features.features.is_empty() {
meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone()));
}
} }
if let Some(parent) = cargo_toml.parent() { if let Some(parent) = cargo_toml.parent() {
meta.current_dir(parent.to_path_buf()); meta.current_dir(parent.to_path_buf());
@ -289,12 +292,16 @@ pub fn load_extern_resources(
cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
if cargo_features.all_features { if cargo_features.all_features {
cmd.arg("--all-features"); cmd.arg("--all-features");
} else if cargo_features.no_default_features {
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
// https://github.com/oli-obk/cargo_metadata/issues/79
cmd.arg("--no-default-features");
} else { } else {
cmd.args(&cargo_features.features); if cargo_features.no_default_features {
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
// https://github.com/oli-obk/cargo_metadata/issues/79
cmd.arg("--no-default-features");
}
if !cargo_features.features.is_empty() {
cmd.arg("--features");
cmd.arg(cargo_features.features.join(" "));
}
} }
let output = cmd.output()?; let output = cmd.output()?;

View file

@ -151,6 +151,7 @@ impl Config {
flycheck: Some(FlycheckConfig::CargoCommand { flycheck: Some(FlycheckConfig::CargoCommand {
command: "check".to_string(), command: "check".to_string(),
target_triple: None, target_triple: None,
no_default_features: false,
all_targets: true, all_targets: true,
all_features: false, all_features: false,
extra_args: Vec::new(), extra_args: Vec::new(),
@ -234,6 +235,9 @@ impl Config {
command: data.checkOnSave_command, command: data.checkOnSave_command,
target_triple: data.checkOnSave_target.or(data.cargo_target), target_triple: data.checkOnSave_target.or(data.cargo_target),
all_targets: data.checkOnSave_allTargets, all_targets: data.checkOnSave_allTargets,
no_default_features: data
.checkOnSave_noDefaultFeatures
.unwrap_or(data.cargo_noDefaultFeatures),
all_features: data.checkOnSave_allFeatures.unwrap_or(data.cargo_allFeatures), all_features: data.checkOnSave_allFeatures.unwrap_or(data.cargo_allFeatures),
features: data.checkOnSave_features.unwrap_or(data.cargo_features), features: data.checkOnSave_features.unwrap_or(data.cargo_features),
extra_args: data.checkOnSave_extraArgs, extra_args: data.checkOnSave_extraArgs,
@ -398,6 +402,7 @@ config_data! {
checkOnSave_allFeatures: Option<bool> = None, checkOnSave_allFeatures: Option<bool> = None,
checkOnSave_allTargets: bool = true, checkOnSave_allTargets: bool = true,
checkOnSave_command: String = "check".into(), checkOnSave_command: String = "check".into(),
checkOnSave_noDefaultFeatures: Option<bool> = None,
checkOnSave_target: Option<String> = None, checkOnSave_target: Option<String> = None,
checkOnSave_extraArgs: Vec<String> = Vec::new(), checkOnSave_extraArgs: Vec<String> = Vec::new(),
checkOnSave_features: Option<Vec<String>> = None, checkOnSave_features: Option<Vec<String>> = None,

View file

@ -323,6 +323,14 @@
"default": true, "default": true,
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
}, },
"rust-analyzer.checkOnSave.noDefaultFeatures": {
"type": [
"null",
"boolean"
],
"default": null,
"markdownDescription": "Do not activate the `default` feature"
},
"rust-analyzer.checkOnSave.allFeatures": { "rust-analyzer.checkOnSave.allFeatures": {
"type": [ "type": [
"null", "null",