Skip to content

Commit 560b98b

Browse files
Merge #4822
4822: Let checkOnSafe default to some of the options of cargo r=matklad a=clemenswasser This will fix #4631 The implementation works (as far as I have tested) but is suboptimal because I am copying the "cargo.features". Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
2 parents c9fc725 + fe21fc2 commit 560b98b

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

crates/ra_flycheck/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ pub use cargo_metadata::diagnostic::{
1818

1919
#[derive(Clone, Debug, PartialEq, Eq)]
2020
pub enum FlycheckConfig {
21-
CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> },
22-
CustomCommand { command: String, args: Vec<String> },
21+
CargoCommand {
22+
command: String,
23+
all_targets: bool,
24+
all_features: bool,
25+
features: Vec<String>,
26+
extra_args: Vec<String>,
27+
},
28+
CustomCommand {
29+
command: String,
30+
args: Vec<String>,
31+
},
2332
}
2433

2534
/// Flycheck wraps the shared state and communication machinery used for
@@ -188,7 +197,13 @@ impl FlycheckThread {
188197
self.check_process = None;
189198

190199
let mut cmd = match &self.config {
191-
FlycheckConfig::CargoCommand { command, all_targets, all_features, extra_args } => {
200+
FlycheckConfig::CargoCommand {
201+
command,
202+
all_targets,
203+
all_features,
204+
extra_args,
205+
features,
206+
} => {
192207
let mut cmd = Command::new(ra_toolchain::cargo());
193208
cmd.arg(command);
194209
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
@@ -198,6 +213,9 @@ impl FlycheckThread {
198213
}
199214
if *all_features {
200215
cmd.arg("--all-features");
216+
} else if !features.is_empty() {
217+
cmd.arg("--features");
218+
cmd.arg(features.join(" "));
201219
}
202220
cmd.args(extra_args);
203221
cmd

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl Default for Config {
147147
all_targets: true,
148148
all_features: false,
149149
extra_args: Vec::new(),
150+
features: Vec::new(),
150151
}),
151152

152153
inlay_hints: InlayHintsConfig {
@@ -234,13 +235,14 @@ impl Config {
234235
}
235236
// otherwise configure command customizations
236237
_ => {
237-
if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets, all_features })
238+
if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets, all_features, features })
238239
= &mut self.check
239240
{
240241
set(value, "/checkOnSave/extraArgs", extra_args);
241242
set(value, "/checkOnSave/command", command);
242243
set(value, "/checkOnSave/allTargets", all_targets);
243-
set(value, "/checkOnSave/allFeatures", all_features);
244+
*all_features = get(value, "/checkOnSave/allFeatures").unwrap_or(self.cargo.all_features);
245+
*features = get(value, "/checkOnSave/features").unwrap_or(self.cargo.features.clone());
244246
}
245247
}
246248
};

editors/code/package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,23 @@
318318
"markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)"
319319
},
320320
"rust-analyzer.checkOnSave.allFeatures": {
321-
"type": "boolean",
322-
"default": false,
323-
"markdownDescription": "Check with all features (will be passed as `--all-features`)"
321+
"type": [
322+
"null",
323+
"boolean"
324+
],
325+
"default": null,
326+
"markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `rust-analyzer.cargo.allFeatures`."
327+
},
328+
"rust-analyzer.checkOnSave.features": {
329+
"type": [
330+
"null",
331+
"array"
332+
],
333+
"items": {
334+
"type": "string"
335+
},
336+
"default": null,
337+
"description": "List of features to activate. Defaults to `rust-analyzer.cargo.features`."
324338
},
325339
"rust-analyzer.inlayHints.enable": {
326340
"type": "boolean",

0 commit comments

Comments
 (0)