aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_vfs/src/io.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs
index 669240488..84ccdb394 100644
--- a/crates/ra_vfs/src/io.rs
+++ b/crates/ra_vfs/src/io.rs
@@ -123,9 +123,7 @@ fn watch_root(
123 .into_iter() 123 .into_iter()
124 .filter_map(|path| { 124 .filter_map(|path| {
125 let abs_path = path.to_path(&config.root); 125 let abs_path = path.to_path(&config.root);
126 let text = fs::read_to_string(abs_path) 126 let text = read_to_string(&abs_path)?;
127 .map_err(|e| log::warn!("watcher error: {}", e))
128 .ok()?;
129 Some((path, text)) 127 Some((path, text))
130 }) 128 })
131 .collect(); 129 .collect();
@@ -194,9 +192,7 @@ impl WatcherCtx {
194 .into_iter() 192 .into_iter()
195 .filter_map(|rel_path| { 193 .filter_map(|rel_path| {
196 let abs_path = rel_path.to_path(&config.root); 194 let abs_path = rel_path.to_path(&config.root);
197 let text = fs::read_to_string(&abs_path) 195 let text = read_to_string(&abs_path)?;
198 .map_err(|e| log::warn!("watcher failed {}", e))
199 .ok()?;
200 Some((rel_path, text)) 196 Some((rel_path, text))
201 }) 197 })
202 .try_for_each(|(path, text)| { 198 .try_for_each(|(path, text)| {
@@ -204,14 +200,15 @@ impl WatcherCtx {
204 .send(TaskResult::AddSingleFile { root, path, text }) 200 .send(TaskResult::AddSingleFile { root, path, text })
205 })? 201 })?
206 } 202 }
207 ChangeKind::Write => match fs::read_to_string(&path) { 203 ChangeKind::Write => {
208 Err(e) => log::warn!("watcher failed {}", e), 204 if let Some(text) = read_to_string(&path) {
209 Ok(text) => self.sender.send(TaskResult::ChangeSingleFile { 205 self.sender.send(TaskResult::ChangeSingleFile {
210 root, 206 root,
211 path: rel_path, 207 path: rel_path,
212 text, 208 text,
213 })?, 209 })?;
214 }, 210 }
211 }
215 ChangeKind::Remove => self.sender.send(TaskResult::RemoveSingleFile { 212 ChangeKind::Remove => self.sender.send(TaskResult::RemoveSingleFile {
216 root, 213 root,
217 path: rel_path, 214 path: rel_path,
@@ -250,3 +247,9 @@ fn watch_one(watcher: &mut RecommendedWatcher, dir: &Path) {
250 Err(e) => log::warn!("could not watch \"{}\": {}", dir.display(), e), 247 Err(e) => log::warn!("could not watch \"{}\": {}", dir.display(), e),
251 } 248 }
252} 249}
250
251fn read_to_string(path: &Path) -> Option<String> {
252 fs::read_to_string(&path)
253 .map_err(|e| log::warn!("failed to read file {}", e))
254 .ok()
255}