aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_vfs/src/io.rs29
-rw-r--r--crates/ra_vfs/src/lib.rs1
-rw-r--r--crates/ra_vfs/tests/vfs.rs2
3 files changed, 10 insertions, 22 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs
index 335f4f2e1..83a021c2f 100644
--- a/crates/ra_vfs/src/io.rs
+++ b/crates/ra_vfs/src/io.rs
@@ -50,7 +50,6 @@ pub enum TaskResult {
50 AddRoot(AddRootResult), 50 AddRoot(AddRootResult),
51 HandleChange(WatcherChange), 51 HandleChange(WatcherChange),
52 LoadChange(WatcherChangeData), 52 LoadChange(WatcherChangeData),
53 NoOp,
54} 53}
55 54
56impl fmt::Debug for TaskResult { 55impl fmt::Debug for TaskResult {
@@ -59,7 +58,6 @@ impl fmt::Debug for TaskResult {
59 TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"), 58 TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"),
60 TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c), 59 TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c),
61 TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c), 60 TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c),
62 TaskResult::NoOp => f.write_str("TaskResult::NoOp"),
63 } 61 }
64 } 62 }
65} 63}
@@ -78,7 +76,7 @@ impl Worker {
78 thread_worker::spawn("vfs", 128, move |input_receiver, output_sender| { 76 thread_worker::spawn("vfs", 128, move |input_receiver, output_sender| {
79 input_receiver 77 input_receiver
80 .into_iter() 78 .into_iter()
81 .map(|t| handle_task(t, &watcher_clone)) 79 .filter_map(|t| handle_task(t, &watcher_clone))
82 .try_for_each(|it| output_sender.send(it)) 80 .try_for_each(|it| output_sender.send(it))
83 .unwrap() 81 .unwrap()
84 }); 82 });
@@ -118,18 +116,12 @@ fn watch(
118 filter_entry: &RootFilter, 116 filter_entry: &RootFilter,
119 emit_for_existing: bool, 117 emit_for_existing: bool,
120) { 118) {
121 let mut watcher = watcher.lock(); 119 if let Some(watcher) = watcher.lock().as_mut() {
122 let watcher = match *watcher { 120 watcher.watch_recursive(dir, filter_entry, emit_for_existing)
123 Some(ref mut w) => w, 121 }
124 None => {
125 // watcher dropped or couldn't start
126 return;
127 }
128 };
129 watcher.watch_recursive(dir, filter_entry, emit_for_existing)
130} 122}
131 123
132fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> TaskResult { 124fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> Option<TaskResult> {
133 match task { 125 match task {
134 Task::AddRoot { 126 Task::AddRoot {
135 root, 127 root,
@@ -145,22 +137,19 @@ fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> TaskResult
145 nested_roots.as_slice(), 137 nested_roots.as_slice(),
146 ); 138 );
147 log::debug!("... loaded {}", path.as_path().display()); 139 log::debug!("... loaded {}", path.as_path().display());
148 TaskResult::AddRoot(AddRootResult { root, files }) 140 Some(TaskResult::AddRoot(AddRootResult { root, files }))
149 } 141 }
150 Task::HandleChange(change) => { 142 Task::HandleChange(change) => {
151 // forward as is because Vfs has to decide if we should load it 143 // forward as is because Vfs has to decide if we should load it
152 TaskResult::HandleChange(change) 144 Some(TaskResult::HandleChange(change))
153 } 145 }
154 Task::LoadChange(change) => { 146 Task::LoadChange(change) => {
155 log::debug!("loading {:?} ...", change); 147 log::debug!("loading {:?} ...", change);
156 match load_change(change) { 148 load_change(change).map(TaskResult::LoadChange)
157 Some(data) => TaskResult::LoadChange(data),
158 None => TaskResult::NoOp,
159 }
160 } 149 }
161 Task::Watch { dir, root_filter } => { 150 Task::Watch { dir, root_filter } => {
162 watch(watcher, &dir, root_filter.as_ref(), true); 151 watch(watcher, &dir, root_filter.as_ref(), true);
163 TaskResult::NoOp 152 None
164 } 153 }
165 } 154 }
166} 155}
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index bcff7928b..f6b45c18a 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -259,7 +259,6 @@ impl Vfs {
259 } 259 }
260 } 260 }
261 }, 261 },
262 TaskResult::NoOp => {}
263 } 262 }
264 } 263 }
265 264
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs
index d3271570a..bf44e97c5 100644
--- a/crates/ra_vfs/tests/vfs.rs
+++ b/crates/ra_vfs/tests/vfs.rs
@@ -117,7 +117,7 @@ fn test_vfs_works() -> std::io::Result<()> {
117 117
118 fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); 118 fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap();
119 fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); 119 fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap();
120 process_tasks(&mut vfs, 4); 120 process_tasks(&mut vfs, 3);
121 assert_match!( 121 assert_match!(
122 vfs.commit_changes().as_slice(), 122 vfs.commit_changes().as_slice(),
123 [VfsChange::AddFile { text, path, .. }], 123 [VfsChange::AddFile { text, path, .. }],