|
3 | 3 |
|
4 | 4 | use std::{fmt, io, process::Command, time::Duration};
|
5 | 5 |
|
6 |
| -use crossbeam_channel::{never, select, unbounded, Receiver, Sender}; |
| 6 | +use crossbeam_channel::{select_biased, unbounded, Receiver, Sender}; |
7 | 7 | use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
|
8 | 8 | use rustc_hash::FxHashMap;
|
9 | 9 | use serde::Deserialize;
|
@@ -260,13 +260,14 @@ impl FlycheckActor {
|
260 | 260 | }
|
261 | 261 |
|
262 | 262 | fn next_event(&self, inbox: &Receiver<StateChange>) -> Option<Event> {
|
263 |
| - if let Ok(msg) = inbox.try_recv() { |
264 |
| - // give restarts a preference so check outputs don't block a restart or stop |
265 |
| - return Some(Event::RequestStateChange(msg)); |
266 |
| - } |
267 |
| - select! { |
| 263 | + let Some(command_receiver) = &self.command_receiver else { |
| 264 | + return inbox.recv().ok().map(Event::RequestStateChange); |
| 265 | + }; |
| 266 | + |
| 267 | + // Biased to give restarts a preference so check outputs don't block a restart or stop |
| 268 | + select_biased! { |
268 | 269 | recv(inbox) -> msg => msg.ok().map(Event::RequestStateChange),
|
269 |
| - recv(self.command_receiver.as_ref().unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())), |
| 270 | + recv(command_receiver) -> msg => Some(Event::CheckEvent(msg.ok())), |
270 | 271 | }
|
271 | 272 | }
|
272 | 273 |
|
@@ -388,7 +389,7 @@ impl FlycheckActor {
|
388 | 389 | package: Option<&str>,
|
389 | 390 | saved_file: Option<&AbsPath>,
|
390 | 391 | ) -> Option<Command> {
|
391 |
| - let (mut cmd, args) = match &self.config { |
| 392 | + match &self.config { |
392 | 393 | FlycheckConfig::CargoCommand { command, options, ansi_color_output } => {
|
393 | 394 | let mut cmd = Command::new(Tool::Cargo.path());
|
394 | 395 | if let Some(sysroot_root) = &self.sysroot_root {
|
@@ -419,7 +420,8 @@ impl FlycheckActor {
|
419 | 420 | cmd.arg("--keep-going");
|
420 | 421 |
|
421 | 422 | options.apply_on_command(&mut cmd);
|
422 |
| - (cmd, options.extra_args.clone()) |
| 423 | + cmd.args(&options.extra_args); |
| 424 | + Some(cmd) |
423 | 425 | }
|
424 | 426 | FlycheckConfig::CustomCommand {
|
425 | 427 | command,
|
@@ -448,34 +450,31 @@ impl FlycheckActor {
|
448 | 450 | }
|
449 | 451 | }
|
450 | 452 |
|
451 |
| - if args.contains(&SAVED_FILE_PLACEHOLDER.to_owned()) { |
452 |
| - // If the custom command has a $saved_file placeholder, and |
453 |
| - // we're saving a file, replace the placeholder in the arguments. |
454 |
| - if let Some(saved_file) = saved_file { |
455 |
| - let args = args |
456 |
| - .iter() |
457 |
| - .map(|arg| { |
458 |
| - if arg == SAVED_FILE_PLACEHOLDER { |
459 |
| - saved_file.to_string() |
460 |
| - } else { |
461 |
| - arg.clone() |
462 |
| - } |
463 |
| - }) |
464 |
| - .collect(); |
465 |
| - (cmd, args) |
466 |
| - } else { |
467 |
| - // The custom command has a $saved_file placeholder, |
468 |
| - // but we had an IDE event that wasn't a file save. Do nothing. |
469 |
| - return None; |
| 453 | + // If the custom command has a $saved_file placeholder, and |
| 454 | + // we're saving a file, replace the placeholder in the arguments. |
| 455 | + if let Some(saved_file) = saved_file { |
| 456 | + for arg in args { |
| 457 | + if arg == SAVED_FILE_PLACEHOLDER { |
| 458 | + cmd.arg(saved_file); |
| 459 | + } else { |
| 460 | + cmd.arg(arg); |
| 461 | + } |
470 | 462 | }
|
471 | 463 | } else {
|
472 |
| - (cmd, args.clone()) |
| 464 | + for arg in args { |
| 465 | + if arg == SAVED_FILE_PLACEHOLDER { |
| 466 | + // The custom command has a $saved_file placeholder, |
| 467 | + // but we had an IDE event that wasn't a file save. Do nothing. |
| 468 | + return None; |
| 469 | + } |
| 470 | + |
| 471 | + cmd.arg(arg); |
| 472 | + } |
473 | 473 | }
|
474 |
| - } |
475 |
| - }; |
476 | 474 |
|
477 |
| - cmd.args(args); |
478 |
| - Some(cmd) |
| 475 | + Some(cmd) |
| 476 | + } |
| 477 | + } |
479 | 478 | }
|
480 | 479 |
|
481 | 480 | #[track_caller]
|
|
0 commit comments