diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 09:16:07 +0000 |
commit | 9a16cf2bf646a4a881f3f5acbf5582dacc4337bf (patch) | |
tree | ff90eb390a8f5af47b6d0c6ec4c49b4431b82d1c /crates/ra_lsp_server/src/vfs.rs | |
parent | dbb62b5baa36783bbca06f09c77794fce3ceff0c (diff) | |
parent | a084412f0698d5f54d586f707930e141c88b0673 (diff) |
Merge #292
292: Vfs r=matklad a=matklad
closes #243
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/vfs.rs')
-rw-r--r-- | crates/ra_lsp_server/src/vfs.rs | 67 |
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 @@ | |||
1 | use std::{ | ||
2 | fs, | ||
3 | path::{Path, PathBuf}, | ||
4 | }; | ||
5 | |||
6 | use walkdir::WalkDir; | ||
7 | use thread_worker::{WorkerHandle, Worker}; | ||
8 | |||
9 | #[derive(Debug)] | ||
10 | pub struct FileEvent { | ||
11 | pub path: PathBuf, | ||
12 | pub kind: FileEventKind, | ||
13 | } | ||
14 | |||
15 | #[derive(Debug)] | ||
16 | pub enum FileEventKind { | ||
17 | Add(String), | ||
18 | } | ||
19 | |||
20 | pub 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 | |||
37 | fn 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 | } | ||