From 684b6fa1b8cd41b03ba485084690f78991820645 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Tue, 9 Jun 2020 21:47:54 +0200 Subject: [PATCH 1/4] flycheck now uses the configured features --- crates/ra_flycheck/src/lib.rs | 24 +++++++++++++++++++++--- crates/rust-analyzer/src/config.rs | 4 +++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index 041e38a9ff..6c41705298 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs @@ -18,8 +18,17 @@ pub use cargo_metadata::diagnostic::{ #[derive(Clone, Debug, PartialEq, Eq)] pub enum FlycheckConfig { - CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec }, - CustomCommand { command: String, args: Vec }, + CargoCommand { + command: String, + all_targets: bool, + all_features: bool, + features: Vec, + extra_args: Vec, + }, + CustomCommand { + command: String, + args: Vec, + }, } /// Flycheck wraps the shared state and communication machinery used for @@ -188,7 +197,13 @@ impl FlycheckThread { self.check_process = None; let mut cmd = match &self.config { - FlycheckConfig::CargoCommand { command, all_targets, all_features, extra_args } => { + FlycheckConfig::CargoCommand { + command, + all_targets, + all_features, + extra_args, + features, + } => { let mut cmd = Command::new(ra_toolchain::cargo()); cmd.arg(command); cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]) @@ -198,6 +213,9 @@ impl FlycheckThread { } if *all_features { cmd.arg("--all-features"); + } else 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 17671f89ee..5d5f7d66a7 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -147,6 +147,7 @@ impl Default for Config { all_targets: true, all_features: false, extra_args: Vec::new(), + features: Vec::new(), }), inlay_hints: InlayHintsConfig { @@ -234,13 +235,14 @@ impl Config { } // otherwise configure command customizations _ => { - if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets, all_features }) + if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets, all_features, features }) = &mut self.check { set(value, "/checkOnSave/extraArgs", extra_args); set(value, "/checkOnSave/command", command); set(value, "/checkOnSave/allTargets", all_targets); set(value, "/checkOnSave/allFeatures", all_features); + *features = self.cargo.features.clone(); } } }; From 47ef544fa57ca1833b466e491315e54a88780b4d Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Wed, 10 Jun 2020 08:51:11 +0200 Subject: [PATCH 2/4] Added the rust-analyzer.checkOnSave.features option. --- crates/rust-analyzer/src/config.rs | 5 ++++- editors/code/package.json | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 5d5f7d66a7..320414ecf3 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -242,7 +242,10 @@ impl Config { set(value, "/checkOnSave/command", command); set(value, "/checkOnSave/allTargets", all_targets); set(value, "/checkOnSave/allFeatures", all_features); - *features = self.cargo.features.clone(); + set(value, "/checkOnSave/features", features); + if features.is_empty() && !self.cargo.features.is_empty() { + *features = self.cargo.features.clone(); + } } } }; diff --git a/editors/code/package.json b/editors/code/package.json index 779d7e1b87..6389499e9a 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -322,6 +322,14 @@ "default": false, "markdownDescription": "Check with all features (will be passed as `--all-features`)" }, + "rust-analyzer.checkOnSave.features": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "List of features to activate. Set to `rust-analyzer.cargo.features` if empty." + }, "rust-analyzer.inlayHints.enable": { "type": "boolean", "default": true, From 33b905883819038ad67476fe14b7b48212a73f93 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Wed, 10 Jun 2020 09:27:25 +0200 Subject: [PATCH 3/4] Most of the checkOnSafe options now default to the cargo equivalent. --- crates/rust-analyzer/src/config.rs | 6 +++++- editors/code/package.json | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 320414ecf3..617612dc3a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -241,7 +241,11 @@ impl Config { set(value, "/checkOnSave/extraArgs", extra_args); set(value, "/checkOnSave/command", command); set(value, "/checkOnSave/allTargets", all_targets); - set(value, "/checkOnSave/allFeatures", all_features); + if let Some(new_all_features) = get(value, "/checkOnSave/allFeatures") { + *all_features = new_all_features; + } else { + *all_features = self.cargo.all_features; + } set(value, "/checkOnSave/features", features); if features.is_empty() && !self.cargo.features.is_empty() { *features = self.cargo.features.clone(); diff --git a/editors/code/package.json b/editors/code/package.json index 6389499e9a..647c83685b 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -318,9 +318,12 @@ "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" }, "rust-analyzer.checkOnSave.allFeatures": { - "type": "boolean", - "default": false, - "markdownDescription": "Check with all features (will be passed as `--all-features`)" + "type": [ + "null", + "boolean" + ], + "default": null, + "markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `rust-analyzer.cargo.allFeatures`." }, "rust-analyzer.checkOnSave.features": { "type": "array", @@ -328,7 +331,7 @@ "type": "string" }, "default": [], - "description": "List of features to activate. Set to `rust-analyzer.cargo.features` if empty." + "description": "List of features to activate. Defaults to `rust-analyzer.cargo.features`." }, "rust-analyzer.inlayHints.enable": { "type": "boolean", From fe21fc2d259cbe2a32bfee3432f2c51ade079083 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Wed, 10 Jun 2020 09:37:26 +0200 Subject: [PATCH 4/4] checkOnSafe.features and checkOnSafe.allFeatures now work identically. --- crates/rust-analyzer/src/config.rs | 11 ++--------- editors/code/package.json | 7 +++++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 617612dc3a..1253db8361 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -241,15 +241,8 @@ impl Config { set(value, "/checkOnSave/extraArgs", extra_args); set(value, "/checkOnSave/command", command); set(value, "/checkOnSave/allTargets", all_targets); - if let Some(new_all_features) = get(value, "/checkOnSave/allFeatures") { - *all_features = new_all_features; - } else { - *all_features = self.cargo.all_features; - } - set(value, "/checkOnSave/features", features); - if features.is_empty() && !self.cargo.features.is_empty() { - *features = self.cargo.features.clone(); - } + *all_features = get(value, "/checkOnSave/allFeatures").unwrap_or(self.cargo.all_features); + *features = get(value, "/checkOnSave/features").unwrap_or(self.cargo.features.clone()); } } }; diff --git a/editors/code/package.json b/editors/code/package.json index 647c83685b..e2027970db 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -326,11 +326,14 @@ "markdownDescription": "Check with all features (will be passed as `--all-features`). Defaults to `rust-analyzer.cargo.allFeatures`." }, "rust-analyzer.checkOnSave.features": { - "type": "array", + "type": [ + "null", + "array" + ], "items": { "type": "string" }, - "default": [], + "default": null, "description": "List of features to activate. Defaults to `rust-analyzer.cargo.features`." }, "rust-analyzer.inlayHints.enable": {