From 8d9f8ac2739e7d02bcbc69e933682c2ef305f987 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Thu, 30 Jul 2020 16:04:01 +0200 Subject: flycheck: Added checkOnSave.noDefaultFeatures This commit adds the option `rust-analyzer.checkOnSave.noDefaultFeatures` and fixes #5550. --- crates/flycheck/src/lib.rs | 13 ++++++++++--- crates/rust-analyzer/src/config.rs | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index ad376ad18..7c38f5ef9 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -24,6 +24,7 @@ pub enum FlycheckConfig { command: String, target_triple: Option, all_targets: bool, + no_default_features: bool, all_features: bool, features: Vec, extra_args: Vec, @@ -180,6 +181,7 @@ impl FlycheckActor { FlycheckConfig::CargoCommand { command, target_triple, + no_default_features, all_targets, all_features, extra_args, @@ -198,9 +200,14 @@ impl FlycheckActor { } if *all_features { cmd.arg("--all-features"); - } else if !features.is_empty() { - cmd.arg("--features"); - cmd.arg(features.join(" ")); + } else { + if *no_default_features { + cmd.arg("--no-default-features"); + } + if !features.is_empty() { + cmd.arg("--features"); + cmd.arg(features.join(" ")); + } } cmd.args(extra_args); cmd diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index e11c8b909..70b4512d0 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -151,6 +151,7 @@ impl Config { flycheck: Some(FlycheckConfig::CargoCommand { command: "check".to_string(), target_triple: None, + no_default_features: false, all_targets: true, all_features: false, extra_args: Vec::new(), @@ -234,6 +235,9 @@ impl Config { command: data.checkOnSave_command, target_triple: data.checkOnSave_target.or(data.cargo_target), 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), features: data.checkOnSave_features.unwrap_or(data.cargo_features), extra_args: data.checkOnSave_extraArgs, @@ -398,6 +402,7 @@ config_data! { checkOnSave_allFeatures: Option = None, checkOnSave_allTargets: bool = true, checkOnSave_command: String = "check".into(), + checkOnSave_noDefaultFeatures: Option = None, checkOnSave_target: Option = None, checkOnSave_extraArgs: Vec = Vec::new(), checkOnSave_features: Option> = None, -- cgit v1.2.3 From 2e562c158fd43d105c0c3f035aafe24c0e648b1e Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Thu, 30 Jul 2020 16:23:07 +0200 Subject: ra_project_model: Fix configuration of features This commit fixes the handling of user-defined configuration of some cargo options. Previously you could either specify `--all-features`, `--no-default-features` or `--features`. Now you can specify either `--all-features` or `--no-default-features` and `--features`. This commit also corrects the `--features` command-line argument creation inside of `load_extern_resources`. --- crates/ra_project_model/src/cargo_workspace.rs | 29 ++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index fb88e0f06..10513542e 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -144,12 +144,15 @@ impl CargoWorkspace { meta.manifest_path(cargo_toml.to_path_buf()); if cargo_features.all_features { meta.features(CargoOpt::AllFeatures); - } else if cargo_features.no_default_features { - // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` - // https://github.com/oli-obk/cargo_metadata/issues/79 - meta.features(CargoOpt::NoDefaultFeatures); - } else if !cargo_features.features.is_empty() { - meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); + } else { + if cargo_features.no_default_features { + // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` + // https://github.com/oli-obk/cargo_metadata/issues/79 + meta.features(CargoOpt::NoDefaultFeatures); + } + if !cargo_features.features.is_empty() { + meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); + } } if let Some(parent) = cargo_toml.parent() { 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); if cargo_features.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 { - 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()?; -- cgit v1.2.3