aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_vfs/src/io.rs53
-rw-r--r--crates/ra_vfs/src/lib.rs7
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
7use walkdir::WalkDir; 7use walkdir::{DirEntry, WalkDir};
8use crossbeam_channel::{Sender, Receiver}; 8use crossbeam_channel::{Sender, Receiver};
9use thread_worker::{WorkerHandle, Worker}; 9use thread_worker::{WorkerHandle};
10
11use crate::VfsRoot;
12
13pub(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)]
12pub struct FileEvent { 22pub(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)]
18pub enum FileEventKind { 28pub(crate) enum FileEventKind {
19 Add(String), 29 Add(String),
20} 30}
21 31
22pub(crate) type FsWorker = Worker<PathBuf, (PathBuf, Vec<FileEvent>)>; 32pub(crate) type Worker = thread_worker::Worker<Task, (PathBuf, Vec<FileEvent>)>;
33
34pub(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
24pub(crate) fn start() -> (FsWorker, WorkerHandle) { 42fn 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
41fn load_root(path: &Path) -> Vec<FileEvent> { 50fn 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
25use relative_path::RelativePathBuf; 25use relative_path::RelativePathBuf;
26use thread_worker::{WorkerHandle, Worker}; 26use thread_worker::{WorkerHandle};
27 27
28use crate::{ 28use 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