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