Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI flag for disabling interrupts #186

Merged
merged 8 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely feels awkward. I tried passing the opts directly in to the relevant function, but the opts are moved into Ghci::new call just below. I can get the bool out here no problem, though, so I do that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is fine.

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