mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
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 <joshmcg88@gmail.com>
This commit is contained in:
commit
25596e1e1a
1 changed files with 25 additions and 15 deletions
|
@ -131,37 +131,47 @@ impl Config {
|
|||
set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
|
||||
set(value, "/cargo/features", &mut self.cargo.features);
|
||||
set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
|
||||
if let Some(mut args) = get::<Vec<String>>(value, "/rustfmt/overrideCommand") {
|
||||
if !args.is_empty() {
|
||||
match get::<Vec<String>>(value, "/rustfmt/overrideCommand") {
|
||||
Some(mut args) if !args.is_empty() => {
|
||||
let command = args.remove(0);
|
||||
self.rustfmt = RustfmtConfig::CustomCommand {
|
||||
command,
|
||||
args,
|
||||
}
|
||||
}
|
||||
} else if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt {
|
||||
set(value, "/rustfmt/extraArgs", extra_args);
|
||||
}
|
||||
_ => {
|
||||
if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt {
|
||||
set(value, "/rustfmt/extraArgs", extra_args);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(false) = get(value, "/checkOnSave/enable") {
|
||||
// check is disabled
|
||||
self.check = None;
|
||||
} else {
|
||||
if let Some(mut args) = get::<Vec<String>>(value, "/checkOnSave/overrideCommand") {
|
||||
if !args.is_empty() {
|
||||
// check is enabled
|
||||
match get::<Vec<String>>(value, "/checkOnSave/overrideCommand") {
|
||||
// first see if the user has completely overridden the command
|
||||
Some(mut args) if !args.is_empty() => {
|
||||
let command = args.remove(0);
|
||||
self.check = Some(FlycheckConfig::CustomCommand {
|
||||
command,
|
||||
args,
|
||||
});
|
||||
}
|
||||
|
||||
} else if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check
|
||||
{
|
||||
set(value, "/checkOnSave/extraArgs", extra_args);
|
||||
set(value, "/checkOnSave/command", command);
|
||||
set(value, "/checkOnSave/allTargets", all_targets);
|
||||
}
|
||||
};
|
||||
// otherwise configure command customizations
|
||||
_ => {
|
||||
if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets })
|
||||
= &mut self.check
|
||||
{
|
||||
set(value, "/checkOnSave/extraArgs", extra_args);
|
||||
set(value, "/checkOnSave/command", command);
|
||||
set(value, "/checkOnSave/allTargets", all_targets);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
set(value, "/inlayHints/typeHints", &mut self.inlay_hints.type_hints);
|
||||
set(value, "/inlayHints/parameterHints", &mut self.inlay_hints.parameter_hints);
|
||||
|
|
Loading…
Reference in a new issue