From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_vfs/src/io.rs | 57 +++++++------------------------- crates/ra_vfs/src/lib.rs | 86 +++++++++--------------------------------------- 2 files changed, 28 insertions(+), 115 deletions(-) (limited to 'crates/ra_vfs/src') diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index d764c534a..ff5ae3a19 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs @@ -14,32 +14,15 @@ use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watc use crate::{RootConfig, Roots, VfsRoot}; pub(crate) enum Task { - AddRoot { - root: VfsRoot, - config: Arc, - }, + AddRoot { root: VfsRoot, config: Arc }, } #[derive(Debug)] pub enum TaskResult { - BulkLoadRoot { - root: VfsRoot, - files: Vec<(RelativePathBuf, String)>, - }, - AddSingleFile { - root: VfsRoot, - path: RelativePathBuf, - text: String, - }, - ChangeSingleFile { - root: VfsRoot, - path: RelativePathBuf, - text: String, - }, - RemoveSingleFile { - root: VfsRoot, - path: RelativePathBuf, - }, + BulkLoadRoot { root: VfsRoot, files: Vec<(RelativePathBuf, String)> }, + AddSingleFile { root: VfsRoot, path: RelativePathBuf, text: String }, + ChangeSingleFile { root: VfsRoot, path: RelativePathBuf, text: String }, + RemoveSingleFile { root: VfsRoot, path: RelativePathBuf }, } #[derive(Debug)] @@ -127,10 +110,7 @@ impl Worker { }, ); - Worker { - worker, - worker_handle, - } + Worker { worker, worker_handle } } pub(crate) fn sender(&self) -> &Sender { @@ -162,9 +142,7 @@ fn watch_root( Some((path, text)) }) .collect(); - sender - .send(TaskResult::BulkLoadRoot { root, files }) - .unwrap(); + sender.send(TaskResult::BulkLoadRoot { root, files }).unwrap(); log::debug!("... loaded {}", config.root.as_path().display()); } @@ -233,21 +211,12 @@ fn handle_change( } ChangeKind::Write => { if let Some(text) = read_to_string(&path) { - sender - .send(TaskResult::ChangeSingleFile { - root, - path: rel_path, - text, - }) - .unwrap(); + sender.send(TaskResult::ChangeSingleFile { root, path: rel_path, text }).unwrap(); } } - ChangeKind::Remove => sender - .send(TaskResult::RemoveSingleFile { - root, - path: rel_path, - }) - .unwrap(), + ChangeKind::Remove => { + sender.send(TaskResult::RemoveSingleFile { root, path: rel_path }).unwrap() + } } } @@ -282,7 +251,5 @@ fn watch_one(watcher: &mut RecommendedWatcher, dir: &Path) { } fn read_to_string(path: &Path) -> Option { - fs::read_to_string(&path) - .map_err(|e| log::warn!("failed to read file {}", e)) - .ok() + fs::read_to_string(&path).map_err(|e| log::warn!("failed to read file {}", e)).ok() } diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 71a3f807d..6b4eb6842 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -58,10 +58,7 @@ impl std::ops::Deref for Roots { impl RootConfig { fn new(root: PathBuf, excluded_dirs: Vec) -> RootConfig { - RootConfig { - root, - excluded_dirs, - } + RootConfig { root, excluded_dirs } } /// Cheks if root contains a path and returns a root-relative path. pub(crate) fn contains(&self, path: &Path) -> Option { @@ -111,9 +108,7 @@ impl Roots { Roots { roots } } pub(crate) fn find(&self, path: &Path) -> Option<(VfsRoot, RelativePathBuf)> { - self.roots - .iter() - .find_map(|(root, data)| data.contains(path).map(|it| (root, it))) + self.roots.iter().find_map(|(root, data)| data.contains(path).map(|it| (root, it))) } } @@ -154,21 +149,10 @@ impl Vfs { for (root, config) in roots.iter() { root2files.insert(root, Default::default()); - worker - .sender() - .send(io::Task::AddRoot { - root, - config: Arc::clone(config), - }) - .unwrap(); + worker.sender().send(io::Task::AddRoot { root, config: Arc::clone(config) }).unwrap(); } - let res = Vfs { - roots, - files: Arena::default(), - root2files, - worker, - pending_changes: Vec::new(), - }; + let res = + Vfs { roots, files: Arena::default(), root2files, worker, pending_changes: Vec::new() }; let vfs_roots = res.roots.iter().map(|(id, _)| id).collect(); (res, vfs_roots) } @@ -205,12 +189,7 @@ impl Vfs { let text = fs::read_to_string(path).unwrap_or_default(); let text = Arc::new(text); let file = self.add_file(root, rel_path.clone(), Arc::clone(&text), false); - let change = VfsChange::AddFile { - file, - text, - root, - path: rel_path, - }; + let change = VfsChange::AddFile { file, text, root, path: rel_path }; self.pending_changes.push(change); Some(file) }; @@ -243,10 +222,7 @@ impl Vfs { cur_files.push((file, path, text)); } - let change = VfsChange::AddRoot { - root, - files: cur_files, - }; + let change = VfsChange::AddRoot { root, files: cur_files }; self.pending_changes.push(change); } TaskResult::AddSingleFile { root, path, text } => { @@ -278,12 +254,7 @@ impl Vfs { ) -> Option { let text = Arc::new(text); let file = self.add_file(root, path.clone(), text.clone(), is_overlay); - self.pending_changes.push(VfsChange::AddFile { - file, - root, - path, - text, - }); + self.pending_changes.push(VfsChange::AddFile { file, root, path, text }); Some(file) } @@ -293,8 +264,7 @@ impl Vfs { } let text = Arc::new(text); self.change_file(file, text.clone(), is_overlay); - self.pending_changes - .push(VfsChange::ChangeFile { file, text }); + self.pending_changes.push(VfsChange::ChangeFile { file, text }); } fn do_remove_file( @@ -308,8 +278,7 @@ impl Vfs { return; } self.remove_file(file); - self.pending_changes - .push(VfsChange::RemoveFile { root, path, file }); + self.pending_changes.push(VfsChange::RemoveFile { root, path, file }); } pub fn add_file_overlay(&mut self, path: &Path, text: String) -> Option { @@ -363,12 +332,7 @@ impl Vfs { text: Arc, is_overlayed: bool, ) -> VfsFile { - let data = VfsFileData { - root, - path, - text, - is_overlayed, - }; + let data = VfsFileData { root, path, text, is_overlayed }; let file = self.files.alloc(data); self.root2files.get_mut(root).unwrap().insert(file); file @@ -396,32 +360,14 @@ impl Vfs { } fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option { - self.root2files[root] - .iter() - .map(|&it| it) - .find(|&file| self.files[file].path == path) + self.root2files[root].iter().map(|&it| it).find(|&file| self.files[file].path == path) } } #[derive(Debug, Clone)] pub enum VfsChange { - AddRoot { - root: VfsRoot, - files: Vec<(VfsFile, RelativePathBuf, Arc)>, - }, - AddFile { - root: VfsRoot, - file: VfsFile, - path: RelativePathBuf, - text: Arc, - }, - RemoveFile { - root: VfsRoot, - file: VfsFile, - path: RelativePathBuf, - }, - ChangeFile { - file: VfsFile, - text: Arc, - }, + AddRoot { root: VfsRoot, files: Vec<(VfsFile, RelativePathBuf, Arc)> }, + AddFile { root: VfsRoot, file: VfsFile, path: RelativePathBuf, text: Arc }, + RemoveFile { root: VfsRoot, file: VfsFile, path: RelativePathBuf }, + ChangeFile { file: VfsFile, text: Arc }, } -- cgit v1.2.3