diff options
author | Aleksey Kladov <[email protected]> | 2018-12-18 10:18:55 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-20 09:15:23 +0000 |
commit | 2ae05a6163d8b15f3d8a18a2ab713d1fbd83c505 (patch) | |
tree | 5d0692d2438ecf5ede416ebbdeab4c9db7c8d5e8 /crates/ra_vfs/src/lib.rs | |
parent | 7509901fa0985f8fc4893a83e0275a063f072dda (diff) |
vfs crate scaffold
Diffstat (limited to 'crates/ra_vfs/src/lib.rs')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 8f6abadb7..b80c12058 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -15,6 +15,7 @@ mod arena; | |||
15 | mod io; | 15 | mod io; |
16 | 16 | ||
17 | use std::{ | 17 | use std::{ |
18 | thread, | ||
18 | cmp::Reverse, | 19 | cmp::Reverse, |
19 | path::{Path, PathBuf}, | 20 | path::{Path, PathBuf}, |
20 | ffi::OsStr, | 21 | ffi::OsStr, |
@@ -22,7 +23,12 @@ use std::{ | |||
22 | }; | 23 | }; |
23 | 24 | ||
24 | use relative_path::RelativePathBuf; | 25 | use relative_path::RelativePathBuf; |
25 | use crate::arena::{ArenaId, Arena}; | 26 | use thread_worker::{WorkerHandle, Worker}; |
27 | |||
28 | use crate::{ | ||
29 | arena::{ArenaId, Arena}, | ||
30 | io::FileEvent, | ||
31 | }; | ||
26 | 32 | ||
27 | /// `RootFilter` is a predicate that checks if a file can belong to a root | 33 | /// `RootFilter` is a predicate that checks if a file can belong to a root |
28 | struct RootFilter { | 34 | struct RootFilter { |
@@ -76,16 +82,24 @@ struct VfsFileData { | |||
76 | text: Arc<String>, | 82 | text: Arc<String>, |
77 | } | 83 | } |
78 | 84 | ||
79 | #[derive(Default)] | ||
80 | struct Vfs { | 85 | struct Vfs { |
81 | roots: Arena<VfsRoot, RootFilter>, | 86 | roots: Arena<VfsRoot, RootFilter>, |
82 | files: Arena<VfsFile, VfsFileData>, | 87 | files: Arena<VfsFile, VfsFileData>, |
83 | // pending_changes: Vec<PendingChange>, | 88 | // pending_changes: Vec<PendingChange>, |
89 | worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, | ||
90 | worker_handle: WorkerHandle, | ||
84 | } | 91 | } |
85 | 92 | ||
86 | impl Vfs { | 93 | impl Vfs { |
87 | pub fn new(mut roots: Vec<PathBuf>) -> Vfs { | 94 | pub fn new(mut roots: Vec<PathBuf>) -> Vfs { |
88 | let mut res = Vfs::default(); | 95 | let (worker, worker_handle) = io::start(); |
96 | |||
97 | let mut res = Vfs { | ||
98 | roots: Arena::default(), | ||
99 | files: Arena::default(), | ||
100 | worker, | ||
101 | worker_handle, | ||
102 | }; | ||
89 | 103 | ||
90 | roots.sort_by_key(|it| Reverse(it.as_os_str().len())); | 104 | roots.sort_by_key(|it| Reverse(it.as_os_str().len())); |
91 | 105 | ||
@@ -104,6 +118,11 @@ impl Vfs { | |||
104 | pub fn commit_changes(&mut self) -> Vec<VfsChange> { | 118 | pub fn commit_changes(&mut self) -> Vec<VfsChange> { |
105 | unimplemented!() | 119 | unimplemented!() |
106 | } | 120 | } |
121 | |||
122 | pub fn shutdown(self) -> thread::Result<()> { | ||
123 | let _ = self.worker.shutdown(); | ||
124 | self.worker_handle.shutdown() | ||
125 | } | ||
107 | } | 126 | } |
108 | 127 | ||
109 | #[derive(Debug, Clone)] | 128 | #[derive(Debug, Clone)] |