refator to move all io to io module

use same channel for scanner and watcher
some implementations pending
This commit is contained in:
Bernardo 2019-01-07 21:35:18 +01:00 committed by Aleksey Kladov
parent d032a1a4e8
commit 6b86f038d6
5 changed files with 136 additions and 103 deletions

View file

@ -10,17 +10,47 @@ use relative_path::RelativePathBuf;
use crate::{VfsRoot, has_rs_extension};
pub(crate) struct Task {
pub(crate) root: VfsRoot,
pub(crate) path: PathBuf,
pub(crate) filter: Box<Fn(&DirEntry) -> bool + Send>,
pub(crate) enum Task {
AddRoot {
root: VfsRoot,
path: PathBuf,
filter: Box<Fn(&DirEntry) -> bool + Send>,
},
WatcherChange(crate::watcher::WatcherChange),
}
pub struct TaskResult {
#[derive(Debug)]
pub struct AddRootResult {
pub(crate) root: VfsRoot,
pub(crate) files: Vec<(RelativePathBuf, String)>,
}
#[derive(Debug)]
pub enum WatcherChangeResult {
Create {
path: PathBuf,
text: String,
},
Write {
path: PathBuf,
text: String,
},
Remove {
path: PathBuf,
},
// can this be replaced and use Remove and Create instead?
Rename {
src: PathBuf,
dst: PathBuf,
text: String,
},
}
pub enum TaskResult {
AddRoot(AddRootResult),
WatcherChange(WatcherChangeResult),
}
impl fmt::Debug for TaskResult {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("TaskResult { ... }")
@ -40,11 +70,18 @@ pub(crate) fn start() -> (Worker, WorkerHandle) {
}
fn handle_task(task: Task) -> TaskResult {
let Task { root, path, filter } = task;
log::debug!("loading {} ...", path.as_path().display());
let files = load_root(path.as_path(), &*filter);
log::debug!("... loaded {}", path.as_path().display());
TaskResult { root, files }
match task {
Task::AddRoot { root, path, filter } => {
log::debug!("loading {} ...", path.as_path().display());
let files = load_root(path.as_path(), &*filter);
log::debug!("... loaded {}", path.as_path().display());
TaskResult::AddRoot(AddRootResult { root, files })
}
Task::WatcherChange(change) => {
// TODO
unimplemented!()
}
}
}
fn load_root(root: &Path, filter: &dyn Fn(&DirEntry) -> bool) -> Vec<(RelativePathBuf, String)> {