diff options
author | Bernardo <[email protected]> | 2019-01-06 17:36:22 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-26 08:46:16 +0000 |
commit | d032a1a4e8c52f4ea38d9ca24070203a35436158 (patch) | |
tree | f1078d87397d5a27e52fa78c474729b55a9c1c5d /crates/ra_vfs/src | |
parent | 1d5eaefe8a8e4f8b267d51ee8ece866741586ada (diff) |
complete test
Diffstat (limited to 'crates/ra_vfs/src')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_vfs/src/watcher.rs | 37 |
2 files changed, 17 insertions, 22 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 5336822b3..1ca94dcd6 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -98,7 +98,7 @@ impl Vfs { | |||
98 | pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) { | 98 | pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) { |
99 | let (worker, worker_handle) = io::start(); | 99 | let (worker, worker_handle) = io::start(); |
100 | 100 | ||
101 | let watcher = Watcher::new().unwrap(); // TODO return Result? | 101 | let watcher = Watcher::start().unwrap(); // TODO return Result? |
102 | 102 | ||
103 | let mut res = Vfs { | 103 | let mut res = Vfs { |
104 | roots: Arena::default(), | 104 | roots: Arena::default(), |
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 | } |