From be14ab217ce29542a8b2c84282e822adcc69646c Mon Sep 17 00:00:00 2001 From: Bernardo Date: Tue, 22 Jan 2019 18:38:34 +0100 Subject: better test, avoid duplicated events --- crates/ra_vfs/src/io.rs | 7 ++++++- crates/ra_vfs/src/io/watcher.rs | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'crates/ra_vfs/src') diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index 3ab52ac3d..335f4f2e1 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs @@ -55,7 +55,12 @@ pub enum TaskResult { impl fmt::Debug for TaskResult { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("TaskResult { ... }") + match self { + TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"), + TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c), + TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c), + TaskResult::NoOp => f.write_str("TaskResult::NoOp"), + } } } diff --git a/crates/ra_vfs/src/io/watcher.rs b/crates/ra_vfs/src/io/watcher.rs index b370c5fbc..68bb6b692 100644 --- a/crates/ra_vfs/src/io/watcher.rs +++ b/crates/ra_vfs/src/io/watcher.rs @@ -100,16 +100,18 @@ impl Watcher { log::warn!("could not watch \"{}\": {}", entry.path().display(), e) } } - } - if emit_for_contents && entry.depth() > 0 { - // emit as create because we haven't seen it yet - if let Err(e) = - self.sender - .send(io::Task::HandleChange(WatcherChange::Create( - entry.path().to_path_buf(), - ))) - { - log::warn!("watcher error: {}", e) + } else { + if emit_for_contents && entry.depth() > 0 { + // emit only for files otherwise we will cause watch_recursive to be called again with a dir that we are already watching + // emit as create because we haven't seen it yet + if let Err(e) = + self.sender + .send(io::Task::HandleChange(WatcherChange::Create( + entry.path().to_path_buf(), + ))) + { + log::warn!("watcher error: {}", e) + } } } } -- cgit v1.2.3