review fixes

This commit is contained in:
Bernardo 2019-01-23 20:43:35 +01:00 committed by Aleksey Kladov
parent 34a34f9399
commit cfbf47b002
3 changed files with 10 additions and 22 deletions

View file

@ -50,7 +50,6 @@ pub enum TaskResult {
AddRoot(AddRootResult), AddRoot(AddRootResult),
HandleChange(WatcherChange), HandleChange(WatcherChange),
LoadChange(WatcherChangeData), LoadChange(WatcherChangeData),
NoOp,
} }
impl fmt::Debug for TaskResult { impl fmt::Debug for TaskResult {
@ -59,7 +58,6 @@ impl fmt::Debug for TaskResult {
TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"), TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"),
TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c), TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c),
TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c), TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c),
TaskResult::NoOp => f.write_str("TaskResult::NoOp"),
} }
} }
} }
@ -78,7 +76,7 @@ impl Worker {
thread_worker::spawn("vfs", 128, move |input_receiver, output_sender| { thread_worker::spawn("vfs", 128, move |input_receiver, output_sender| {
input_receiver input_receiver
.into_iter() .into_iter()
.map(|t| handle_task(t, &watcher_clone)) .filter_map(|t| handle_task(t, &watcher_clone))
.try_for_each(|it| output_sender.send(it)) .try_for_each(|it| output_sender.send(it))
.unwrap() .unwrap()
}); });
@ -118,18 +116,12 @@ fn watch(
filter_entry: &RootFilter, filter_entry: &RootFilter,
emit_for_existing: bool, emit_for_existing: bool,
) { ) {
let mut watcher = watcher.lock(); if let Some(watcher) = watcher.lock().as_mut() {
let watcher = match *watcher {
Some(ref mut w) => w,
None => {
// watcher dropped or couldn't start
return;
}
};
watcher.watch_recursive(dir, filter_entry, emit_for_existing) watcher.watch_recursive(dir, filter_entry, emit_for_existing)
} }
}
fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> TaskResult { fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> Option<TaskResult> {
match task { match task {
Task::AddRoot { Task::AddRoot {
root, root,
@ -145,22 +137,19 @@ fn handle_task(task: Task, watcher: &Arc<Mutex<Option<Watcher>>>) -> TaskResult
nested_roots.as_slice(), nested_roots.as_slice(),
); );
log::debug!("... loaded {}", path.as_path().display()); log::debug!("... loaded {}", path.as_path().display());
TaskResult::AddRoot(AddRootResult { root, files }) Some(TaskResult::AddRoot(AddRootResult { root, files }))
} }
Task::HandleChange(change) => { Task::HandleChange(change) => {
// forward as is because Vfs has to decide if we should load it // forward as is because Vfs has to decide if we should load it
TaskResult::HandleChange(change) Some(TaskResult::HandleChange(change))
} }
Task::LoadChange(change) => { Task::LoadChange(change) => {
log::debug!("loading {:?} ...", change); log::debug!("loading {:?} ...", change);
match load_change(change) { load_change(change).map(TaskResult::LoadChange)
Some(data) => TaskResult::LoadChange(data),
None => TaskResult::NoOp,
}
} }
Task::Watch { dir, root_filter } => { Task::Watch { dir, root_filter } => {
watch(watcher, &dir, root_filter.as_ref(), true); watch(watcher, &dir, root_filter.as_ref(), true);
TaskResult::NoOp None
} }
} }
} }

View file

@ -259,7 +259,6 @@ impl Vfs {
} }
} }
}, },
TaskResult::NoOp => {}
} }
} }

View file

@ -117,7 +117,7 @@ fn test_vfs_works() -> std::io::Result<()> {
fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap();
fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap();
process_tasks(&mut vfs, 4); process_tasks(&mut vfs, 3);
assert_match!( assert_match!(
vfs.commit_changes().as_slice(), vfs.commit_changes().as_slice(),
[VfsChange::AddFile { text, path, .. }], [VfsChange::AddFile { text, path, .. }],