]> git.lizzy.rs Git - rust.git/commitdiff
add io::Task
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 18 Dec 2018 10:35:05 +0000 (13:35 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 20 Dec 2018 09:15:23 +0000 (12:15 +0300)
crates/ra_vfs/src/io.rs
crates/ra_vfs/src/lib.rs

index 257f1bf538657c45180fa92328ac26399a532fc5..c467605835ba51fcff63845676db95340f2e4518 100644 (file)
@@ -4,38 +4,47 @@
     thread::JoinHandle,
 };
 
-use walkdir::WalkDir;
+use walkdir::{DirEntry, WalkDir};
 use crossbeam_channel::{Sender, Receiver};
-use thread_worker::{WorkerHandle, Worker};
+use thread_worker::{WorkerHandle};
+
+use crate::VfsRoot;
+
+pub(crate) enum Task {
+    ScanRoot {
+        root: VfsRoot,
+        path: PathBuf,
+        filter: Box<FnMut(&DirEntry) -> bool + Send>,
+    },
+}
 
 #[derive(Debug)]
-pub struct FileEvent {
-    pub path: PathBuf,
-    pub kind: FileEventKind,
+pub(crate) struct FileEvent {
+    pub(crate) path: PathBuf,
+    pub(crate) kind: FileEventKind,
 }
 
 #[derive(Debug)]
-pub enum FileEventKind {
+pub(crate) enum FileEventKind {
     Add(String),
 }
 
-pub(crate) type FsWorker = Worker<PathBuf, (PathBuf, Vec<FileEvent>)>;
+pub(crate) type Worker = thread_worker::Worker<Task, (PathBuf, Vec<FileEvent>)>;
+
+pub(crate) fn start() -> (Worker, WorkerHandle) {
+    thread_worker::spawn("vfs", 128, |input_receiver, output_sender| {
+        input_receiver
+            .map(handle_task)
+            .for_each(|it| output_sender.send(it))
+    })
+}
 
-pub(crate) fn start() -> (FsWorker, WorkerHandle) {
-    thread_worker::spawn::<PathBuf, (PathBuf, Vec<FileEvent>), _>(
-        "vfs",
-        128,
-        |input_receiver, output_sender| {
-            input_receiver
-                .map(|path| {
-                    log::debug!("loading {} ...", path.as_path().display());
-                    let events = load_root(path.as_path());
-                    log::debug!("... loaded {}", path.as_path().display());
-                    (path, events)
-                })
-                .for_each(|it| output_sender.send(it))
-        },
-    )
+fn handle_task(task: Task) -> (PathBuf, Vec<FileEvent>) {
+    let Task::ScanRoot { path, .. } = task;
+    log::debug!("loading {} ...", path.as_path().display());
+    let events = load_root(path.as_path());
+    log::debug!("... loaded {}", path.as_path().display());
+    (path, events)
 }
 
 fn load_root(path: &Path) -> Vec<FileEvent> {
index d4ba2cb4550ffc7488049b59ce9a5c9c11cb1fbc..8ce6b6ee0a73e28922089b6acce5cf0d591f145e 100644 (file)
@@ -2,8 +2,8 @@
 //!
 //! When doing analysis, we don't want to do any IO, we want to keep all source
 //! code in memory. However, the actual source code is stored on disk, so you
-//! need to get it into the memory in the first place somehow. VFS is the
 //! component which does this.
+//! need to get it into the memory in the first place somehow. VFS is the
 //!
 //! It also is responsible for watching the disk for changes, and for merging
 //! editor state (modified, unsaved files) with disk state.
 };
 
 use relative_path::RelativePathBuf;
-use thread_worker::{WorkerHandle, Worker};
+use thread_worker::{WorkerHandle};
 
 use crate::{
     arena::{ArenaId, Arena},
-    io::{FileEvent, FsWorker},
 };
 
 /// `RootFilter` is a predicate that checks if a file can belong to a root. If
@@ -87,7 +86,7 @@ struct Vfs {
     roots: Arena<VfsRoot, RootFilter>,
     files: Arena<VfsFile, VfsFileData>,
     // pending_changes: Vec<PendingChange>,
-    worker: FsWorker,
+    worker: io::Worker,
     worker_handle: WorkerHandle,
 }