diff options
Diffstat (limited to 'crates/ra_vfs/src/io.rs')
-rw-r--r-- | crates/ra_vfs/src/io.rs | 117 |
1 files changed, 57 insertions, 60 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index f90fe0e84..ce3271d48 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs | |||
@@ -6,67 +6,64 @@ use std::{ | |||
6 | 6 | ||
7 | use walkdir::WalkDir; | 7 | use walkdir::WalkDir; |
8 | use crossbeam_channel::{Sender, Receiver}; | 8 | use crossbeam_channel::{Sender, Receiver}; |
9 | use thread_worker::{WorkerHandle, Worker}; | ||
9 | 10 | ||
10 | pub(crate) fn start_io() -> (JoinHandle<(), Sender<()>, Receiver()>) {} | 11 | #[derive(Debug)] |
12 | pub struct FileEvent { | ||
13 | pub path: PathBuf, | ||
14 | pub kind: FileEventKind, | ||
15 | } | ||
11 | 16 | ||
12 | // use crate::thread_watcher::{ThreadWatcher, Worker}; | 17 | #[derive(Debug)] |
18 | pub enum FileEventKind { | ||
19 | Add(String), | ||
20 | } | ||
13 | 21 | ||
14 | // #[derive(Debug)] | 22 | pub fn start() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, WorkerHandle) { |
15 | // pub struct FileEvent { | 23 | thread_worker::spawn::<PathBuf, (PathBuf, Vec<FileEvent>), _>( |
16 | // pub path: PathBuf, | 24 | "vfs", |
17 | // pub kind: FileEventKind, | 25 | 128, |
18 | // } | 26 | |input_receiver, output_sender| { |
27 | input_receiver | ||
28 | .map(|path| { | ||
29 | log::debug!("loading {} ...", path.as_path().display()); | ||
30 | let events = load_root(path.as_path()); | ||
31 | log::debug!("... loaded {}", path.as_path().display()); | ||
32 | (path, events) | ||
33 | }) | ||
34 | .for_each(|it| output_sender.send(it)) | ||
35 | }, | ||
36 | ) | ||
37 | } | ||
19 | 38 | ||
20 | // #[derive(Debug)] | 39 | fn load_root(path: &Path) -> Vec<FileEvent> { |
21 | // pub enum FileEventKind { | 40 | let mut res = Vec::new(); |
22 | // Add(String), | 41 | for entry in WalkDir::new(path) { |
23 | // } | 42 | let entry = match entry { |
24 | 43 | Ok(entry) => entry, | |
25 | // pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatcher) { | 44 | Err(e) => { |
26 | // Worker::<PathBuf, (PathBuf, Vec<FileEvent>)>::spawn( | 45 | log::warn!("watcher error: {}", e); |
27 | // "roots loader", | 46 | continue; |
28 | // 128, | 47 | } |
29 | // |input_receiver, output_sender| { | 48 | }; |
30 | // input_receiver | 49 | if !entry.file_type().is_file() { |
31 | // .map(|path| { | 50 | continue; |
32 | // log::debug!("loading {} ...", path.as_path().display()); | 51 | } |
33 | // let events = load_root(path.as_path()); | 52 | let path = entry.path(); |
34 | // log::debug!("... loaded {}", path.as_path().display()); | 53 | if path.extension().and_then(|os| os.to_str()) != Some("rs") { |
35 | // (path, events) | 54 | continue; |
36 | // }) | 55 | } |
37 | // .for_each(|it| output_sender.send(it)) | 56 | let text = match fs::read_to_string(path) { |
38 | // }, | 57 | Ok(text) => text, |
39 | // ) | 58 | Err(e) => { |
40 | // } | 59 | log::warn!("watcher error: {}", e); |
41 | 60 | continue; | |
42 | // fn load_root(path: &Path) -> Vec<FileEvent> { | 61 | } |
43 | // let mut res = Vec::new(); | 62 | }; |
44 | // for entry in WalkDir::new(path) { | 63 | res.push(FileEvent { |
45 | // let entry = match entry { | 64 | path: path.to_owned(), |
46 | // Ok(entry) => entry, | 65 | kind: FileEventKind::Add(text), |
47 | // Err(e) => { | 66 | }) |
48 | // log::warn!("watcher error: {}", e); | 67 | } |
49 | // continue; | 68 | res |
50 | // } | 69 | } |
51 | // }; | ||
52 | // if !entry.file_type().is_file() { | ||
53 | // continue; | ||
54 | // } | ||
55 | // let path = entry.path(); | ||
56 | // if path.extension().and_then(|os| os.to_str()) != Some("rs") { | ||
57 | // continue; | ||
58 | // } | ||
59 | // let text = match fs::read_to_string(path) { | ||
60 | // Ok(text) => text, | ||
61 | // Err(e) => { | ||
62 | // log::warn!("watcher error: {}", e); | ||
63 | // continue; | ||
64 | // } | ||
65 | // }; | ||
66 | // res.push(FileEvent { | ||
67 | // path: path.to_owned(), | ||
68 | // kind: FileEventKind::Add(text), | ||
69 | // }) | ||
70 | // } | ||
71 | // res | ||
72 | // } | ||