Skip to content

Commit

Permalink
CLI flag for disabling interrupts (#186)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
parsonsmatt and 9999years committed Dec 13, 2023
1 parent d2725f3 commit cb14c86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/ghci/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`")?;
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/ghci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
})
Expand Down

0 comments on commit cb14c86

Please sign in to comment.