diff options
Diffstat (limited to 'crates/ra_vfs/src/watcher.rs')
-rw-r--r-- | crates/ra_vfs/src/watcher.rs | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/crates/ra_vfs/src/watcher.rs b/crates/ra_vfs/src/watcher.rs index cc05f949e..1aac23616 100644 --- a/crates/ra_vfs/src/watcher.rs +++ b/crates/ra_vfs/src/watcher.rs | |||
@@ -39,7 +39,6 @@ impl WatcherChange { | |||
39 | DebouncedEvent::Remove(path) => Some(WatcherChange::Remove(path)), | 39 | DebouncedEvent::Remove(path) => Some(WatcherChange::Remove(path)), |
40 | DebouncedEvent::Rename(src, dst) => Some(WatcherChange::Rename(src, dst)), | 40 | DebouncedEvent::Rename(src, dst) => Some(WatcherChange::Rename(src, dst)), |
41 | DebouncedEvent::Error(err, path) => { | 41 | DebouncedEvent::Error(err, path) => { |
42 | // TODO | ||
43 | log::warn!("watch error {}, {:?}", err, path); | 42 | log::warn!("watch error {}, {:?}", err, path); |
44 | None | 43 | None |
45 | } | 44 | } |
@@ -48,23 +47,17 @@ impl WatcherChange { | |||
48 | } | 47 | } |
49 | 48 | ||
50 | impl Watcher { | 49 | impl Watcher { |
51 | pub fn new() -> Result<Watcher, Box<std::error::Error>> { | 50 | pub fn start() -> Result<Watcher, Box<std::error::Error>> { |
52 | let (input_sender, input_receiver) = mpsc::channel(); | 51 | let (input_sender, input_receiver) = mpsc::channel(); |
53 | let watcher = notify::watcher(input_sender, Duration::from_millis(250))?; | 52 | let watcher = notify::watcher(input_sender, Duration::from_millis(250))?; |
54 | let (output_sender, output_receiver) = crossbeam_channel::unbounded(); | 53 | let (output_sender, output_receiver) = crossbeam_channel::unbounded(); |
55 | let thread = thread::spawn(move || loop { | 54 | let thread = thread::spawn(move || { |
56 | match input_receiver.recv() { | 55 | input_receiver |
57 | Ok(ev) => { | 56 | .into_iter() |
58 | // forward relevant events only | 57 | // forward relevant events only |
59 | if let Some(change) = WatcherChange::from_debounced_event(ev) { | 58 | .filter_map(WatcherChange::from_debounced_event) |
60 | output_sender.send(change).unwrap(); | 59 | .try_for_each(|change| output_sender.send(change)) |
61 | } | 60 | .unwrap() |
62 | } | ||
63 | Err(err) => { | ||
64 | log::debug!("Watcher stopped ({})", err); | ||
65 | break; | ||
66 | } | ||
67 | } | ||
68 | }); | 61 | }); |
69 | Ok(Watcher { | 62 | Ok(Watcher { |
70 | receiver: output_receiver, | 63 | receiver: output_receiver, |
@@ -86,11 +79,13 @@ impl Watcher { | |||
86 | pub fn shutdown(mut self) -> thread::Result<()> { | 79 | pub fn shutdown(mut self) -> thread::Result<()> { |
87 | self.bomb.defuse(); | 80 | self.bomb.defuse(); |
88 | drop(self.watcher); | 81 | drop(self.watcher); |
89 | let res = self.thread.join(); | 82 | // TODO this doesn't terminate for some reason |
90 | match &res { | 83 | // let res = self.thread.join(); |
91 | Ok(()) => log::info!("... Watcher terminated with ok"), | 84 | // match &res { |
92 | Err(_) => log::error!("... Watcher terminated with err"), | 85 | // Ok(()) => log::info!("... Watcher terminated with ok"), |
93 | } | 86 | // Err(_) => log::error!("... Watcher terminated with err"), |
94 | res | 87 | // } |
88 | // res | ||
89 | Ok(()) | ||
95 | } | 90 | } |
96 | } | 91 | } |