Skip to content

Commit 6b7cb8b

Browse files
Merge #5596
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>
2 parents 7d18109 + 2e562c1 commit 6b7cb8b

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

crates/flycheck/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum FlycheckConfig {
2424
command: String,
2525
target_triple: Option<String>,
2626
all_targets: bool,
27+
no_default_features: bool,
2728
all_features: bool,
2829
features: Vec<String>,
2930
extra_args: Vec<String>,
@@ -180,6 +181,7 @@ impl FlycheckActor {
180181
FlycheckConfig::CargoCommand {
181182
command,
182183
target_triple,
184+
no_default_features,
183185
all_targets,
184186
all_features,
185187
extra_args,
@@ -198,9 +200,14 @@ impl FlycheckActor {
198200
}
199201
if *all_features {
200202
cmd.arg("--all-features");
201-
} else if !features.is_empty() {
202-
cmd.arg("--features");
203-
cmd.arg(features.join(" "));
203+
} else {
204+
if *no_default_features {
205+
cmd.arg("--no-default-features");
206+
}
207+
if !features.is_empty() {
208+
cmd.arg("--features");
209+
cmd.arg(features.join(" "));
210+
}
204211
}
205212
cmd.args(extra_args);
206213
cmd

crates/ra_project_model/src/cargo_workspace.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ impl CargoWorkspace {
144144
meta.manifest_path(cargo_toml.to_path_buf());
145145
if cargo_features.all_features {
146146
meta.features(CargoOpt::AllFeatures);
147-
} else if cargo_features.no_default_features {
148-
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
149-
// https://github.com/oli-obk/cargo_metadata/issues/79
150-
meta.features(CargoOpt::NoDefaultFeatures);
151-
} else if !cargo_features.features.is_empty() {
152-
meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone()));
147+
} else {
148+
if cargo_features.no_default_features {
149+
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
150+
// https://github.com/oli-obk/cargo_metadata/issues/79
151+
meta.features(CargoOpt::NoDefaultFeatures);
152+
}
153+
if !cargo_features.features.is_empty() {
154+
meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone()));
155+
}
153156
}
154157
if let Some(parent) = cargo_toml.parent() {
155158
meta.current_dir(parent.to_path_buf());
@@ -289,12 +292,16 @@ pub fn load_extern_resources(
289292
cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
290293
if cargo_features.all_features {
291294
cmd.arg("--all-features");
292-
} else if cargo_features.no_default_features {
293-
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
294-
// https://github.com/oli-obk/cargo_metadata/issues/79
295-
cmd.arg("--no-default-features");
296295
} else {
297-
cmd.args(&cargo_features.features);
296+
if cargo_features.no_default_features {
297+
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
298+
// https://github.com/oli-obk/cargo_metadata/issues/79
299+
cmd.arg("--no-default-features");
300+
}
301+
if !cargo_features.features.is_empty() {
302+
cmd.arg("--features");
303+
cmd.arg(cargo_features.features.join(" "));
304+
}
298305
}
299306

300307
let output = cmd.output()?;

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl Config {
151151
flycheck: Some(FlycheckConfig::CargoCommand {
152152
command: "check".to_string(),
153153
target_triple: None,
154+
no_default_features: false,
154155
all_targets: true,
155156
all_features: false,
156157
extra_args: Vec::new(),
@@ -234,6 +235,9 @@ impl Config {
234235
command: data.checkOnSave_command,
235236
target_triple: data.checkOnSave_target.or(data.cargo_target),
236237
all_targets: data.checkOnSave_allTargets,
238+
no_default_features: data
239+
.checkOnSave_noDefaultFeatures
240+
.unwrap_or(data.cargo_noDefaultFeatures),
237241
all_features: data.checkOnSave_allFeatures.unwrap_or(data.cargo_allFeatures),
238242
features: data.checkOnSave_features.unwrap_or(data.cargo_features),
239243
extra_args: data.checkOnSave_extraArgs,
@@ -398,6 +402,7 @@ config_data! {
398402
checkOnSave_allFeatures: Option<bool> = None,
399403
checkOnSave_allTargets: bool = true,
400404
checkOnSave_command: String = "check".into(),
405+
checkOnSave_noDefaultFeatures: Option<bool> = None,
401406
checkOnSave_target: Option<String> = None,
402407
checkOnSave_extraArgs: Vec<String> = Vec::new(),
403408
checkOnSave_features: Option<Vec<String>> = None,

editors/code/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@
323323
"default": true,
324324
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
325325
},
326+
"rust-analyzer.checkOnSave.noDefaultFeatures": {
327+
"type": [
328+
"null",
329+
"boolean"
330+
],
331+
"default": null,
332+
"markdownDescription": "Do not activate the `default` feature"
333+
},
326334
"rust-analyzer.checkOnSave.allFeatures": {
327335
"type": [
328336
"null",

0 commit comments

Comments
 (0)