diff options
author | Aleksey Kladov <[email protected]> | 2018-12-18 10:35:05 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-20 09:15:23 +0000 |
commit | e69b05781f7fb0f0dfdcd4acb433dbcde9cbb7b7 (patch) | |
tree | 3117cbb25cca518646f03e68bd91f7dc36aea571 /crates | |
parent | 99561cf2f20ad572c7149644a70cd7740c0f8b86 (diff) |
add io::Task
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_vfs/src/io.rs | 53 | ||||
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 7 |
2 files changed, 34 insertions, 26 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index 257f1bf53..c46760583 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs | |||
@@ -4,38 +4,47 @@ use std::{ | |||
4 | thread::JoinHandle, | 4 | thread::JoinHandle, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use walkdir::WalkDir; | 7 | use walkdir::{DirEntry, WalkDir}; |
8 | use crossbeam_channel::{Sender, Receiver}; | 8 | use crossbeam_channel::{Sender, Receiver}; |
9 | use thread_worker::{WorkerHandle, Worker}; | 9 | use thread_worker::{WorkerHandle}; |
10 | |||
11 | use crate::VfsRoot; | ||
12 | |||
13 | pub(crate) enum Task { | ||
14 | ScanRoot { | ||
15 | root: VfsRoot, | ||
16 | path: PathBuf, | ||
17 | filter: Box<FnMut(&DirEntry) -> bool + Send>, | ||
18 | }, | ||
19 | } | ||
10 | 20 | ||
11 | #[derive(Debug)] | 21 | #[derive(Debug)] |
12 | pub struct FileEvent { | 22 | pub(crate) struct FileEvent { |
13 | pub path: PathBuf, | 23 | pub(crate) path: PathBuf, |
14 | pub kind: FileEventKind, | 24 | pub(crate) kind: FileEventKind, |
15 | } | 25 | } |
16 | 26 | ||
17 | #[derive(Debug)] | 27 | #[derive(Debug)] |
18 | pub enum FileEventKind { | 28 | pub(crate) enum FileEventKind { |
19 | Add(String), | 29 | Add(String), |
20 | } | 30 | } |
21 | 31 | ||
22 | pub(crate) type FsWorker = Worker<PathBuf, (PathBuf, Vec<FileEvent>)>; | 32 | pub(crate) type Worker = thread_worker::Worker<Task, (PathBuf, Vec<FileEvent>)>; |
33 | |||
34 | pub(crate) fn start() -> (Worker, WorkerHandle) { | ||
35 | thread_worker::spawn("vfs", 128, |input_receiver, output_sender| { | ||
36 | input_receiver | ||
37 | .map(handle_task) | ||
38 | .for_each(|it| output_sender.send(it)) | ||
39 | }) | ||
40 | } | ||
23 | 41 | ||
24 | pub(crate) fn start() -> (FsWorker, WorkerHandle) { | 42 | fn handle_task(task: Task) -> (PathBuf, Vec<FileEvent>) { |
25 | thread_worker::spawn::<PathBuf, (PathBuf, Vec<FileEvent>), _>( | 43 | let Task::ScanRoot { path, .. } = task; |
26 | "vfs", | 44 | log::debug!("loading {} ...", path.as_path().display()); |
27 | 128, | 45 | let events = load_root(path.as_path()); |
28 | |input_receiver, output_sender| { | 46 | log::debug!("... loaded {}", path.as_path().display()); |
29 | input_receiver | 47 | (path, events) |
30 | .map(|path| { | ||
31 | log::debug!("loading {} ...", path.as_path().display()); | ||
32 | let events = load_root(path.as_path()); | ||
33 | log::debug!("... loaded {}", path.as_path().display()); | ||
34 | (path, events) | ||
35 | }) | ||
36 | .for_each(|it| output_sender.send(it)) | ||
37 | }, | ||
38 | ) | ||
39 | } | 48 | } |
40 | 49 | ||
41 | fn load_root(path: &Path) -> Vec<FileEvent> { | 50 | fn load_root(path: &Path) -> Vec<FileEvent> { |
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index d4ba2cb45..8ce6b6ee0 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -2,8 +2,8 @@ | |||
2 | //! | 2 | //! |
3 | //! When doing analysis, we don't want to do any IO, we want to keep all source | 3 | //! When doing analysis, we don't want to do any IO, we want to keep all source |
4 | //! code in memory. However, the actual source code is stored on disk, so you | 4 | //! code in memory. However, the actual source code is stored on disk, so you |
5 | //! need to get it into the memory in the first place somehow. VFS is the | ||
6 | //! component which does this. | 5 | //! component which does this. |
6 | //! need to get it into the memory in the first place somehow. VFS is the | ||
7 | //! | 7 | //! |
8 | //! It also is responsible for watching the disk for changes, and for merging | 8 | //! It also is responsible for watching the disk for changes, and for merging |
9 | //! editor state (modified, unsaved files) with disk state. | 9 | //! editor state (modified, unsaved files) with disk state. |
@@ -23,11 +23,10 @@ use std::{ | |||
23 | }; | 23 | }; |
24 | 24 | ||
25 | use relative_path::RelativePathBuf; | 25 | use relative_path::RelativePathBuf; |
26 | use thread_worker::{WorkerHandle, Worker}; | 26 | use thread_worker::{WorkerHandle}; |
27 | 27 | ||
28 | use crate::{ | 28 | use crate::{ |
29 | arena::{ArenaId, Arena}, | 29 | arena::{ArenaId, Arena}, |
30 | io::{FileEvent, FsWorker}, | ||
31 | }; | 30 | }; |
32 | 31 | ||
33 | /// `RootFilter` is a predicate that checks if a file can belong to a root. If | 32 | /// `RootFilter` is a predicate that checks if a file can belong to a root. If |
@@ -87,7 +86,7 @@ struct Vfs { | |||
87 | roots: Arena<VfsRoot, RootFilter>, | 86 | roots: Arena<VfsRoot, RootFilter>, |
88 | files: Arena<VfsFile, VfsFileData>, | 87 | files: Arena<VfsFile, VfsFileData>, |
89 | // pending_changes: Vec<PendingChange>, | 88 | // pending_changes: Vec<PendingChange>, |
90 | worker: FsWorker, | 89 | worker: io::Worker, |
91 | worker_handle: WorkerHandle, | 90 | worker_handle: WorkerHandle, |
92 | } | 91 | } |
93 | 92 | ||