aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/src/io.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs/src/io.rs')
-rw-r--r--crates/ra_vfs/src/io.rs57
1 files changed, 12 insertions, 45 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs
index d764c534a..ff5ae3a19 100644
--- a/crates/ra_vfs/src/io.rs
+++ b/crates/ra_vfs/src/io.rs
@@ -14,32 +14,15 @@ use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watc
14use crate::{RootConfig, Roots, VfsRoot}; 14use crate::{RootConfig, Roots, VfsRoot};
15 15
16pub(crate) enum Task { 16pub(crate) enum Task {
17 AddRoot { 17 AddRoot { root: VfsRoot, config: Arc<RootConfig> },
18 root: VfsRoot,
19 config: Arc<RootConfig>,
20 },
21} 18}
22 19
23#[derive(Debug)] 20#[derive(Debug)]
24pub enum TaskResult { 21pub enum TaskResult {
25 BulkLoadRoot { 22 BulkLoadRoot { root: VfsRoot, files: Vec<(RelativePathBuf, String)> },
26 root: VfsRoot, 23 AddSingleFile { root: VfsRoot, path: RelativePathBuf, text: String },
27 files: Vec<(RelativePathBuf, String)>, 24 ChangeSingleFile { root: VfsRoot, path: RelativePathBuf, text: String },
28 }, 25 RemoveSingleFile { root: VfsRoot, path: RelativePathBuf },
29 AddSingleFile {
30 root: VfsRoot,
31 path: RelativePathBuf,
32 text: String,
33 },
34 ChangeSingleFile {
35 root: VfsRoot,
36 path: RelativePathBuf,
37 text: String,
38 },
39 RemoveSingleFile {
40 root: VfsRoot,
41 path: RelativePathBuf,
42 },
43} 26}
44 27
45#[derive(Debug)] 28#[derive(Debug)]
@@ -127,10 +110,7 @@ impl Worker {
127 }, 110 },
128 ); 111 );
129 112
130 Worker { 113 Worker { worker, worker_handle }
131 worker,
132 worker_handle,
133 }
134 } 114 }
135 115
136 pub(crate) fn sender(&self) -> &Sender<Task> { 116 pub(crate) fn sender(&self) -> &Sender<Task> {
@@ -162,9 +142,7 @@ fn watch_root(
162 Some((path, text)) 142 Some((path, text))
163 }) 143 })
164 .collect(); 144 .collect();
165 sender 145 sender.send(TaskResult::BulkLoadRoot { root, files }).unwrap();
166 .send(TaskResult::BulkLoadRoot { root, files })
167 .unwrap();
168 log::debug!("... loaded {}", config.root.as_path().display()); 146 log::debug!("... loaded {}", config.root.as_path().display());
169} 147}
170 148
@@ -233,21 +211,12 @@ fn handle_change(
233 } 211 }
234 ChangeKind::Write => { 212 ChangeKind::Write => {
235 if let Some(text) = read_to_string(&path) { 213 if let Some(text) = read_to_string(&path) {
236 sender 214 sender.send(TaskResult::ChangeSingleFile { root, path: rel_path, text }).unwrap();
237 .send(TaskResult::ChangeSingleFile {
238 root,
239 path: rel_path,
240 text,
241 })
242 .unwrap();
243 } 215 }
244 } 216 }
245 ChangeKind::Remove => sender 217 ChangeKind::Remove => {
246 .send(TaskResult::RemoveSingleFile { 218 sender.send(TaskResult::RemoveSingleFile { root, path: rel_path }).unwrap()
247 root, 219 }
248 path: rel_path,
249 })
250 .unwrap(),
251 } 220 }
252} 221}
253 222
@@ -282,7 +251,5 @@ fn watch_one(watcher: &mut RecommendedWatcher, dir: &Path) {
282} 251}
283 252
284fn read_to_string(path: &Path) -> Option<String> { 253fn read_to_string(path: &Path) -> Option<String> {
285 fs::read_to_string(&path) 254 fs::read_to_string(&path).map_err(|e| log::warn!("failed to read file {}", e)).ok()
286 .map_err(|e| log::warn!("failed to read file {}", e))
287 .ok()
288} 255}