Skip to content
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
18 changes: 9 additions & 9 deletions src/ghci/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ use super::Ghci;
use super::GhciOpts;
use super::GhciReloadKind;

/// An event sent to [`Ghci`].
/// An event sent to [`Ghci`] by the watcher.
#[derive(Debug, Clone)]
pub enum GhciEvent {
pub enum WatcherEvent {
/// Reload the `ghci` session.
Reload {
/// The file events to respond to.
events: BTreeSet<FileEvent>,
},
}

impl GhciEvent {
impl WatcherEvent {
/// When we interrupt an event to reload, add the file events together so that we don't lose
/// work.
fn merge(&mut self, other: GhciEvent) {
fn merge(&mut self, other: WatcherEvent) {
match (self, other) {
(
GhciEvent::Reload { events },
GhciEvent::Reload {
WatcherEvent::Reload { events },
WatcherEvent::Reload {
events: other_events,
},
) => {
Expand All @@ -53,7 +53,7 @@ impl GhciEvent {
pub async fn run_ghci(
mut handle: ShutdownHandle,
opts: GhciOpts,
mut receiver: mpsc::Receiver<GhciEvent>,
mut receiver: mpsc::Receiver<WatcherEvent>,
) -> miette::Result<()> {
// 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.
Expand Down Expand Up @@ -144,11 +144,11 @@ pub async fn run_ghci(
#[instrument(level = "debug", skip(ghci, reload_sender))]
async fn dispatch(
ghci: Arc<Mutex<Ghci>>,
event: GhciEvent,
event: WatcherEvent,
reload_sender: oneshot::Sender<GhciReloadKind>,
) -> miette::Result<()> {
match event {
GhciEvent::Reload { events } => {
WatcherEvent::Reload { events } => {
ghci.lock().await.reload(events, reload_sender).await?;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing::instrument;

use crate::cli::Opts;
use crate::event_filter::file_events_from_action;
use crate::ghci::manager::GhciEvent;
use crate::ghci::manager::WatcherEvent;
use crate::normal_path::NormalPath;
use crate::shutdown::ShutdownHandle;

Expand Down Expand Up @@ -51,7 +51,7 @@ impl WatcherOpts {
#[instrument(level = "debug", skip_all)]
pub async fn run_watcher(
handle: ShutdownHandle,
ghci_sender: mpsc::Sender<GhciEvent>,
ghci_sender: mpsc::Sender<WatcherEvent>,
opts: WatcherOpts,
) -> miette::Result<()> {
if opts.poll.is_some() {
Expand All @@ -63,7 +63,7 @@ pub async fn run_watcher(

async fn run_debouncer<T: notify::Watcher>(
mut handle: ShutdownHandle,
ghci_sender: mpsc::Sender<GhciEvent>,
ghci_sender: mpsc::Sender<WatcherEvent>,
opts: WatcherOpts,
) -> miette::Result<()> {
let mut config = notify::Config::default();
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn run_debouncer<T: notify::Watcher>(

struct EventHandler {
handle: Handle,
ghci_sender: mpsc::Sender<GhciEvent>,
ghci_sender: mpsc::Sender<WatcherEvent>,
shutdown: ShutdownHandle,
}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl EventHandler {
} else {
tracing::trace!(?events, "Processed events");
self.ghci_sender
.send(GhciEvent::Reload { events })
.send(WatcherEvent::Reload { events })
.await
.into_diagnostic()?;
}
Expand Down