diff options
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 3eeec8b1c..f698e3e86 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -86,7 +86,7 @@ pub struct Vfs { | |||
86 | pending_changes: Vec<VfsChange>, | 86 | pending_changes: Vec<VfsChange>, |
87 | worker: io::Worker, | 87 | worker: io::Worker, |
88 | worker_handle: WorkerHandle, | 88 | worker_handle: WorkerHandle, |
89 | watcher: Watcher, | 89 | watcher: Option<Watcher>, |
90 | } | 90 | } |
91 | 91 | ||
92 | impl fmt::Debug for Vfs { | 92 | impl fmt::Debug for Vfs { |
@@ -99,7 +99,13 @@ impl Vfs { | |||
99 | pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) { | 99 | pub fn new(mut roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) { |
100 | let (worker, worker_handle) = io::start(); | 100 | let (worker, worker_handle) = io::start(); |
101 | 101 | ||
102 | let watcher = Watcher::start(worker.inp.clone()).unwrap(); // TODO return Result? | 102 | let watcher = match Watcher::start(worker.inp.clone()) { |
103 | Ok(watcher) => Some(watcher), | ||
104 | Err(e) => { | ||
105 | log::error!("could not start watcher: {}", e); | ||
106 | None | ||
107 | } | ||
108 | }; | ||
103 | 109 | ||
104 | let mut res = Vfs { | 110 | let mut res = Vfs { |
105 | roots: Arena::default(), | 111 | roots: Arena::default(), |
@@ -134,7 +140,11 @@ impl Vfs { | |||
134 | filter: Box::new(filter), | 140 | filter: Box::new(filter), |
135 | }; | 141 | }; |
136 | res.worker.inp.send(task).unwrap(); | 142 | res.worker.inp.send(task).unwrap(); |
137 | res.watcher.watch(path).unwrap(); | 143 | if let Some(ref mut watcher) = res.watcher { |
144 | if let Err(e) = watcher.watch(path) { | ||
145 | log::warn!("could not watch \"{}\": {}", path.display(), e); | ||
146 | } | ||
147 | } | ||
138 | } | 148 | } |
139 | let roots = res.roots.iter().map(|(id, _)| id).collect(); | 149 | let roots = res.roots.iter().map(|(id, _)| id).collect(); |
140 | (res, roots) | 150 | (res, roots) |
@@ -350,7 +360,9 @@ impl Vfs { | |||
350 | 360 | ||
351 | /// Sutdown the VFS and terminate the background watching thread. | 361 | /// Sutdown the VFS and terminate the background watching thread. |
352 | pub fn shutdown(self) -> thread::Result<()> { | 362 | pub fn shutdown(self) -> thread::Result<()> { |
353 | let _ = self.watcher.shutdown(); | 363 | if let Some(watcher) = self.watcher { |
364 | let _ = watcher.shutdown(); | ||
365 | } | ||
354 | let _ = self.worker.shutdown(); | 366 | let _ = self.worker.shutdown(); |
355 | self.worker_handle.shutdown() | 367 | self.worker_handle.shutdown() |
356 | } | 368 | } |