From cb14c8627a9a6b097729df5f47b364ce72c0c25e Mon Sep 17 00:00:00 2001 From: "Matt von Hagen (Parsons)" Date: Wed, 13 Dec 2023 13:30:11 -0700 Subject: [PATCH] CLI flag for disabling interrupts (#186) This PR adds a cli flag that disables the interrupt behavior for reloads. This is my first contribution to a Rust project so I'm sure it'll take some polishing :) --------- Co-authored-by: Rebecca Turner --- src/cli.rs | 6 ++++++ src/ghci/manager.rs | 3 ++- src/ghci/mod.rs | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 5acdb4f4..82fa8d31 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -49,6 +49,12 @@ pub struct Opts { /// Options to modify logging and error-handling behavior. #[command(flatten)] pub logging: LoggingOpts, + + /// Don't interrupt reloads when files change. + /// + /// Depending on your workflow, `ghciwatch` may feel more responsive with this set. + #[arg(long)] + pub no_interrupt_reloads: bool, } /// Options for watching files. diff --git a/src/ghci/manager.rs b/src/ghci/manager.rs index 4cf3fdfb..48ed72cd 100644 --- a/src/ghci/manager.rs +++ b/src/ghci/manager.rs @@ -56,6 +56,7 @@ pub async fn run_ghci( // This function is pretty tricky! We need to handle shutdowns at each stage, and the process // is a little different each time, so the `select!`s can't be consolidated. + let no_interrupt_reloads = opts.no_interrupt_reloads; let mut ghci = Ghci::new(handle.clone(), opts) .await .wrap_err("Failed to start `ghci`")?; @@ -113,7 +114,7 @@ pub async fn run_ghci( } Some(new_event) = receiver.recv() => { tracing::debug!(?new_event, "Received ghci event from watcher while reloading"); - if should_interrupt(reload_receiver).await { + if !no_interrupt_reloads && should_interrupt(reload_receiver).await { // Merge the events together so we don't lose progress. // Then, the next iteration of the loop will pick up the `maybe_event` value // and respond immediately. diff --git a/src/ghci/mod.rs b/src/ghci/mod.rs index 66cb44e0..79901c0f 100644 --- a/src/ghci/mod.rs +++ b/src/ghci/mod.rs @@ -102,6 +102,8 @@ pub struct GhciOpts { pub restart_globs: GlobMatcher, /// Reload the `ghci` session when paths matching these globs are changed. pub reload_globs: GlobMatcher, + /// Determines whether we should interrupt a reload in progress or not. + pub no_interrupt_reloads: bool, /// Where to write what `ghci` emits to `stdout`. Inherits parent's `stdout` by default. pub stdout_writer: GhciWriter, /// Where to write what `ghci` emits to `stderr`. Inherits parent's `stderr` by default. @@ -128,6 +130,7 @@ impl GhciOpts { hooks: opts.hooks.clone(), restart_globs: opts.watch.restart_globs()?, reload_globs: opts.watch.reload_globs()?, + no_interrupt_reloads: opts.no_interrupt_reloads, stdout_writer: GhciWriter::stdout(), stderr_writer: GhciWriter::stderr(), })