diff options
author | Aleksey Kladov <[email protected]> | 2019-02-17 17:22:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-17 17:22:46 +0000 |
commit | 162dea51bfa6b7f6d64d138a84c16c96495a0fcd (patch) | |
tree | f321f11cd0d9c88c8c684f65312041d8db5598d2 /crates/ra_vfs/src/io.rs | |
parent | 6b5d90972ae2f288ae7cf57e209c0d5d8c7a1fd2 (diff) |
hide root config
Diffstat (limited to 'crates/ra_vfs/src/io.rs')
-rw-r--r-- | crates/ra_vfs/src/io.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index f64b4c532..0cffc03f3 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs | |||
@@ -9,10 +9,10 @@ use relative_path::RelativePathBuf; | |||
9 | use walkdir::WalkDir; | 9 | use walkdir::WalkDir; |
10 | use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watcher}; | 10 | use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watcher}; |
11 | 11 | ||
12 | use crate::{RootConfig, Roots, VfsRoot}; | 12 | use crate::{Roots, VfsRoot}; |
13 | 13 | ||
14 | pub(crate) enum Task { | 14 | pub(crate) enum Task { |
15 | AddRoot { root: VfsRoot, config: Arc<RootConfig> }, | 15 | AddRoot { root: VfsRoot }, |
16 | } | 16 | } |
17 | 17 | ||
18 | /// `TaskResult` transfers files read on the IO thread to the VFS on the main | 18 | /// `TaskResult` transfers files read on the IO thread to the VFS on the main |
@@ -98,8 +98,8 @@ pub(crate) fn start(roots: Arc<Roots>) -> Worker { | |||
98 | drop(input_receiver); | 98 | drop(input_receiver); |
99 | break | 99 | break |
100 | }, | 100 | }, |
101 | Ok(Task::AddRoot { root, config }) => { | 101 | Ok(Task::AddRoot { root }) => { |
102 | watch_root(watcher.as_mut(), &output_sender, root, Arc::clone(&config)); | 102 | watch_root(watcher.as_mut(), &output_sender, &*roots, root); |
103 | } | 103 | } |
104 | }, | 104 | }, |
105 | // Watcher send us changes. If **this** channel is | 105 | // Watcher send us changes. If **this** channel is |
@@ -123,20 +123,21 @@ pub(crate) fn start(roots: Arc<Roots>) -> Worker { | |||
123 | fn watch_root( | 123 | fn watch_root( |
124 | watcher: Option<&mut RecommendedWatcher>, | 124 | watcher: Option<&mut RecommendedWatcher>, |
125 | sender: &Sender<TaskResult>, | 125 | sender: &Sender<TaskResult>, |
126 | roots: &Roots, | ||
126 | root: VfsRoot, | 127 | root: VfsRoot, |
127 | config: Arc<RootConfig>, | ||
128 | ) { | 128 | ) { |
129 | log::debug!("loading {} ...", config.root.as_path().display()); | 129 | let root_path = roots.path(root); |
130 | let files = watch_recursive(watcher, config.root.as_path(), &*config) | 130 | log::debug!("loading {} ...", root_path.display()); |
131 | let files = watch_recursive(watcher, root_path, roots, root) | ||
131 | .into_iter() | 132 | .into_iter() |
132 | .filter_map(|path| { | 133 | .filter_map(|path| { |
133 | let abs_path = path.to_path(&config.root); | 134 | let abs_path = path.to_path(&root_path); |
134 | let text = read_to_string(&abs_path)?; | 135 | let text = read_to_string(&abs_path)?; |
135 | Some((path, text)) | 136 | Some((path, text)) |
136 | }) | 137 | }) |
137 | .collect(); | 138 | .collect(); |
138 | sender.send(TaskResult::BulkLoadRoot { root, files }).unwrap(); | 139 | sender.send(TaskResult::BulkLoadRoot { root, files }).unwrap(); |
139 | log::debug!("... loaded {}", config.root.as_path().display()); | 140 | log::debug!("... loaded {}", root_path.display()); |
140 | } | 141 | } |
141 | 142 | ||
142 | fn convert_notify_event(event: DebouncedEvent, sender: &Sender<(PathBuf, ChangeKind)>) { | 143 | fn convert_notify_event(event: DebouncedEvent, sender: &Sender<(PathBuf, ChangeKind)>) { |
@@ -181,19 +182,18 @@ fn handle_change( | |||
181 | None => return, | 182 | None => return, |
182 | Some(it) => it, | 183 | Some(it) => it, |
183 | }; | 184 | }; |
184 | let config = &roots[root]; | ||
185 | match kind { | 185 | match kind { |
186 | ChangeKind::Create => { | 186 | ChangeKind::Create => { |
187 | let mut paths = Vec::new(); | 187 | let mut paths = Vec::new(); |
188 | if path.is_dir() { | 188 | if path.is_dir() { |
189 | paths.extend(watch_recursive(watcher, &path, &config)); | 189 | paths.extend(watch_recursive(watcher, &path, roots, root)); |
190 | } else { | 190 | } else { |
191 | paths.push(rel_path); | 191 | paths.push(rel_path); |
192 | } | 192 | } |
193 | paths | 193 | paths |
194 | .into_iter() | 194 | .into_iter() |
195 | .try_for_each(|rel_path| { | 195 | .try_for_each(|rel_path| { |
196 | let abs_path = rel_path.to_path(&config.root); | 196 | let abs_path = rel_path.to_path(&roots.path(root)); |
197 | let text = read_to_string(&abs_path); | 197 | let text = read_to_string(&abs_path); |
198 | sender.send(TaskResult::SingleFile { root, path: rel_path, text }) | 198 | sender.send(TaskResult::SingleFile { root, path: rel_path, text }) |
199 | }) | 199 | }) |
@@ -209,12 +209,13 @@ fn handle_change( | |||
209 | fn watch_recursive( | 209 | fn watch_recursive( |
210 | mut watcher: Option<&mut RecommendedWatcher>, | 210 | mut watcher: Option<&mut RecommendedWatcher>, |
211 | dir: &Path, | 211 | dir: &Path, |
212 | config: &RootConfig, | 212 | roots: &Roots, |
213 | root: VfsRoot, | ||
213 | ) -> Vec<RelativePathBuf> { | 214 | ) -> Vec<RelativePathBuf> { |
214 | let mut files = Vec::new(); | 215 | let mut files = Vec::new(); |
215 | for entry in WalkDir::new(dir) | 216 | for entry in WalkDir::new(dir) |
216 | .into_iter() | 217 | .into_iter() |
217 | .filter_entry(|it| config.contains(it.path()).is_some()) | 218 | .filter_entry(|it| roots.contains(root, it.path()).is_some()) |
218 | .filter_map(|it| it.map_err(|e| log::warn!("watcher error: {}", e)).ok()) | 219 | .filter_map(|it| it.map_err(|e| log::warn!("watcher error: {}", e)).ok()) |
219 | { | 220 | { |
220 | if entry.file_type().is_dir() { | 221 | if entry.file_type().is_dir() { |
@@ -222,7 +223,7 @@ fn watch_recursive( | |||
222 | watch_one(watcher, entry.path()); | 223 | watch_one(watcher, entry.path()); |
223 | } | 224 | } |
224 | } else { | 225 | } else { |
225 | let path = config.contains(entry.path()).unwrap(); | 226 | let path = roots.contains(root, entry.path()).unwrap(); |
226 | files.push(path.to_owned()); | 227 | files.push(path.to_owned()); |
227 | } | 228 | } |
228 | } | 229 | } |