mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Simplify check_command
while avoiding allocations
This commit is contained in:
parent
56f63dfd8a
commit
cb1c7b3b99
1 changed files with 25 additions and 27 deletions
|
@ -388,7 +388,7 @@ impl FlycheckActor {
|
|||
package: Option<&str>,
|
||||
saved_file: Option<&AbsPath>,
|
||||
) -> Option<Command> {
|
||||
let (mut cmd, args) = match &self.config {
|
||||
match &self.config {
|
||||
FlycheckConfig::CargoCommand { command, options, ansi_color_output } => {
|
||||
let mut cmd = Command::new(Tool::Cargo.path());
|
||||
if let Some(sysroot_root) = &self.sysroot_root {
|
||||
|
@ -419,7 +419,8 @@ impl FlycheckActor {
|
|||
cmd.arg("--keep-going");
|
||||
|
||||
options.apply_on_command(&mut cmd);
|
||||
(cmd, options.extra_args.clone())
|
||||
cmd.args(&options.extra_args);
|
||||
Some(cmd)
|
||||
}
|
||||
FlycheckConfig::CustomCommand {
|
||||
command,
|
||||
|
@ -448,35 +449,32 @@ impl FlycheckActor {
|
|||
}
|
||||
}
|
||||
|
||||
if args.contains(&SAVED_FILE_PLACEHOLDER.to_owned()) {
|
||||
// If the custom command has a $saved_file placeholder, and
|
||||
// we're saving a file, replace the placeholder in the arguments.
|
||||
if let Some(saved_file) = saved_file {
|
||||
let args = args
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
for arg in args {
|
||||
if arg == SAVED_FILE_PLACEHOLDER {
|
||||
saved_file.to_string()
|
||||
cmd.arg(saved_file);
|
||||
} else {
|
||||
arg.clone()
|
||||
cmd.arg(arg);
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
(cmd, args)
|
||||
} else {
|
||||
for arg in args {
|
||||
if arg == SAVED_FILE_PLACEHOLDER {
|
||||
// The custom command has a $saved_file placeholder,
|
||||
// but we had an IDE event that wasn't a file save. Do nothing.
|
||||
return None;
|
||||
}
|
||||
} else {
|
||||
(cmd, args.clone())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cmd.args(args);
|
||||
cmd.arg(arg);
|
||||
}
|
||||
}
|
||||
|
||||
Some(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn send(&self, check_task: FlycheckMessage) {
|
||||
(self.sender)(check_task);
|
||||
|
|
Loading…
Reference in a new issue