aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-07 07:48:04 +0100
committerGitHub <[email protected]>2020-04-07 07:48:04 +0100
commit25596e1e1a579eb7643fda1d8013925342ea5a1e (patch)
tree141457681118671f58c055321b6a8f80f713224a /crates
parentc859a6480af7baece2eec38c19f71cb714db9e3b (diff)
parent8f7fceeb9ceab6383deae8895c88b3ba53f8dabe (diff)
Merge #3872
3872: fix cargo check config with custom command r=matklad a=JoshMcguigan fixes #3871 Previously if `get::<Vec<String>>(value, "/checkOnSave/overrideCommand")` returned `Some` we'd never execute `set(value, "/checkOnSave/command", command)`, even if the `overrideCommand` was empty. I am not sure of the best way to prove this, but I believe the LSP clients send this config with a default value if it is not set by the user, which means `get::<Vec<String>>(value, "/checkOnSave/overrideCommand")` would return `Some(vec![])` and thus we'd never set the command to the user specified value (in the case of #3871, "clippy"). I have tested this fix manually by installing this modified version of rust-analyzer and verifying I can see clippy lints in my editor (`coc.nvim`) with `rust-analyzer.checkOnSave.command": "clippy"`. As best I can tell this would have affected rustfmt extra args too, so this PR also applies the same fix there. Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs40
1 files changed, 25 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index b6a015790..4734df16a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -131,37 +131,47 @@ impl Config {
131 set(value, "/cargo/allFeatures", &mut self.cargo.all_features); 131 set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
132 set(value, "/cargo/features", &mut self.cargo.features); 132 set(value, "/cargo/features", &mut self.cargo.features);
133 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); 133 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
134 if let Some(mut args) = get::<Vec<String>>(value, "/rustfmt/overrideCommand") { 134 match get::<Vec<String>>(value, "/rustfmt/overrideCommand") {
135 if !args.is_empty() { 135 Some(mut args) if !args.is_empty() => {
136 let command = args.remove(0); 136 let command = args.remove(0);
137 self.rustfmt = RustfmtConfig::CustomCommand { 137 self.rustfmt = RustfmtConfig::CustomCommand {
138 command, 138 command,
139 args, 139 args,
140 } 140 }
141 } 141 }
142 } else if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { 142 _ => {
143 set(value, "/rustfmt/extraArgs", extra_args); 143 if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt {
144 } 144 set(value, "/rustfmt/extraArgs", extra_args);
145 }
146 }
147 };
145 148
146 if let Some(false) = get(value, "/checkOnSave/enable") { 149 if let Some(false) = get(value, "/checkOnSave/enable") {
150 // check is disabled
147 self.check = None; 151 self.check = None;
148 } else { 152 } else {
149 if let Some(mut args) = get::<Vec<String>>(value, "/checkOnSave/overrideCommand") { 153 // check is enabled
150 if !args.is_empty() { 154 match get::<Vec<String>>(value, "/checkOnSave/overrideCommand") {
155 // first see if the user has completely overridden the command
156 Some(mut args) if !args.is_empty() => {
151 let command = args.remove(0); 157 let command = args.remove(0);
152 self.check = Some(FlycheckConfig::CustomCommand { 158 self.check = Some(FlycheckConfig::CustomCommand {
153 command, 159 command,
154 args, 160 args,
155 }); 161 });
156 } 162 }
157 163 // otherwise configure command customizations
158 } else if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check 164 _ => {
159 { 165 if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets })
160 set(value, "/checkOnSave/extraArgs", extra_args); 166 = &mut self.check
161 set(value, "/checkOnSave/command", command); 167 {
162 set(value, "/checkOnSave/allTargets", all_targets); 168 set(value, "/checkOnSave/extraArgs", extra_args);
163 } 169 set(value, "/checkOnSave/command", command);
164 }; 170 set(value, "/checkOnSave/allTargets", all_targets);
171 }
172 }
173 };
174 }
165 175
166 set(value, "/inlayHints/typeHints", &mut self.inlay_hints.type_hints); 176 set(value, "/inlayHints/typeHints", &mut self.inlay_hints.type_hints);
167 set(value, "/inlayHints/parameterHints", &mut self.inlay_hints.parameter_hints); 177 set(value, "/inlayHints/parameterHints", &mut self.inlay_hints.parameter_hints);