aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs')
-rw-r--r--crates/ra_vfs/src/lib.rs14
-rw-r--r--crates/ra_vfs/src/roots.rs20
2 files changed, 18 insertions, 16 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index 7f555a3c0..1c5402aed 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -25,7 +25,7 @@ use std::{
25}; 25};
26 26
27use crossbeam_channel::Receiver; 27use crossbeam_channel::Receiver;
28use ra_arena::{impl_arena_id, Arena, RawId, map::ArenaMap}; 28use ra_arena::{impl_arena_id, Arena, RawId};
29use relative_path::{RelativePath, RelativePathBuf}; 29use relative_path::{RelativePath, RelativePathBuf};
30use rustc_hash::{FxHashMap, FxHashSet}; 30use rustc_hash::{FxHashMap, FxHashSet};
31 31
@@ -53,7 +53,7 @@ struct VfsFileData {
53pub struct Vfs { 53pub struct Vfs {
54 roots: Arc<Roots>, 54 roots: Arc<Roots>,
55 files: Arena<VfsFile, VfsFileData>, 55 files: Arena<VfsFile, VfsFileData>,
56 root2files: ArenaMap<VfsRoot, FxHashSet<VfsFile>>, 56 root2files: FxHashMap<VfsRoot, FxHashSet<VfsFile>>,
57 pending_changes: Vec<VfsChange>, 57 pending_changes: Vec<VfsChange>,
58 worker: Worker, 58 worker: Worker,
59} 59}
@@ -72,7 +72,7 @@ impl Vfs {
72 pub fn new(roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) { 72 pub fn new(roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) {
73 let roots = Arc::new(Roots::new(roots)); 73 let roots = Arc::new(Roots::new(roots));
74 let worker = io::start(Arc::clone(&roots)); 74 let worker = io::start(Arc::clone(&roots));
75 let mut root2files = ArenaMap::default(); 75 let mut root2files = FxHashMap::default();
76 76
77 for root in roots.iter() { 77 for root in roots.iter() {
78 root2files.insert(root, Default::default()); 78 root2files.insert(root, Default::default());
@@ -164,7 +164,7 @@ impl Vfs {
164 let mut cur_files = Vec::new(); 164 let mut cur_files = Vec::new();
165 // While we were scanning the root in the background, a file might have 165 // While we were scanning the root in the background, a file might have
166 // been open in the editor, so we need to account for that. 166 // been open in the editor, so we need to account for that.
167 let existing = self.root2files[root] 167 let existing = self.root2files[&root]
168 .iter() 168 .iter()
169 .map(|&file| (self.files[file].path.clone(), file)) 169 .map(|&file| (self.files[file].path.clone(), file))
170 .collect::<FxHashMap<_, _>>(); 170 .collect::<FxHashMap<_, _>>();
@@ -241,7 +241,7 @@ impl Vfs {
241 ) -> VfsFile { 241 ) -> VfsFile {
242 let data = VfsFileData { root, path, text, is_overlayed }; 242 let data = VfsFileData { root, path, text, is_overlayed };
243 let file = self.files.alloc(data); 243 let file = self.files.alloc(data);
244 self.root2files.get_mut(root).unwrap().insert(file); 244 self.root2files.get_mut(&root).unwrap().insert(file);
245 file 245 file
246 } 246 }
247 247
@@ -256,7 +256,7 @@ impl Vfs {
256 self.files[file].text = Default::default(); 256 self.files[file].text = Default::default();
257 self.files[file].path = Default::default(); 257 self.files[file].path = Default::default();
258 let root = self.files[file].root; 258 let root = self.files[file].root;
259 let removed = self.root2files.get_mut(root).unwrap().remove(&file); 259 let removed = self.root2files.get_mut(&root).unwrap().remove(&file);
260 assert!(removed); 260 assert!(removed);
261 } 261 }
262 262
@@ -267,7 +267,7 @@ impl Vfs {
267 } 267 }
268 268
269 fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option<VfsFile> { 269 fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option<VfsFile> {
270 self.root2files[root].iter().map(|&it| it).find(|&file| self.files[file].path == path) 270 self.root2files[&root].iter().map(|&it| it).find(|&file| self.files[file].path == path)
271 } 271 }
272} 272}
273 273
diff --git a/crates/ra_vfs/src/roots.rs b/crates/ra_vfs/src/roots.rs
index 9d3918502..4503458ee 100644
--- a/crates/ra_vfs/src/roots.rs
+++ b/crates/ra_vfs/src/roots.rs
@@ -4,12 +4,10 @@ use std::{
4}; 4};
5 5
6use relative_path::{ RelativePath, RelativePathBuf}; 6use relative_path::{ RelativePath, RelativePathBuf};
7use ra_arena::{impl_arena_id, Arena, RawId};
8 7
9/// VfsRoot identifies a watched directory on the file system. 8/// VfsRoot identifies a watched directory on the file system.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct VfsRoot(pub RawId); 10pub struct VfsRoot(pub u32);
12impl_arena_id!(VfsRoot);
13 11
14/// Describes the contents of a single source root. 12/// Describes the contents of a single source root.
15/// 13///
@@ -24,12 +22,12 @@ struct RootData {
24} 22}
25 23
26pub(crate) struct Roots { 24pub(crate) struct Roots {
27 roots: Arena<VfsRoot, RootData>, 25 roots: Vec<RootData>,
28} 26}
29 27
30impl Roots { 28impl Roots {
31 pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots { 29 pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots {
32 let mut roots = Arena::default(); 30 let mut roots = Vec::new();
33 // A hack to make nesting work. 31 // A hack to make nesting work.
34 paths.sort_by_key(|it| std::cmp::Reverse(it.as_os_str().len())); 32 paths.sort_by_key(|it| std::cmp::Reverse(it.as_os_str().len()));
35 paths.dedup(); 33 paths.dedup();
@@ -37,7 +35,7 @@ impl Roots {
37 let nested_roots = 35 let nested_roots =
38 paths[..i].iter().filter_map(|it| rel_path(path, it)).collect::<Vec<_>>(); 36 paths[..i].iter().filter_map(|it| rel_path(path, it)).collect::<Vec<_>>();
39 37
40 roots.alloc(RootData::new(path.clone(), nested_roots)); 38 roots.push(RootData::new(path.clone(), nested_roots));
41 } 39 }
42 Roots { roots } 40 Roots { roots }
43 } 41 }
@@ -51,20 +49,24 @@ impl Roots {
51 self.roots.len() 49 self.roots.len()
52 } 50 }
53 pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = VfsRoot> + 'a { 51 pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = VfsRoot> + 'a {
54 self.roots.iter().map(|(id, _)| id) 52 (0..self.roots.len()).into_iter().map(|idx| VfsRoot(idx as u32))
55 } 53 }
56 pub(crate) fn path(&self, root: VfsRoot) -> &Path { 54 pub(crate) fn path(&self, root: VfsRoot) -> &Path {
57 self.roots[root].path.as_path() 55 self.root(root).path.as_path()
58 } 56 }
59 /// Checks if root contains a path and returns a root-relative path. 57 /// Checks if root contains a path and returns a root-relative path.
60 pub(crate) fn contains(&self, root: VfsRoot, path: &Path) -> Option<RelativePathBuf> { 58 pub(crate) fn contains(&self, root: VfsRoot, path: &Path) -> Option<RelativePathBuf> {
61 let data = &self.roots[root]; 59 let data = self.root(root);
62 iter::once(&data.path) 60 iter::once(&data.path)
63 .chain(data.canonical_path.as_ref().into_iter()) 61 .chain(data.canonical_path.as_ref().into_iter())
64 .find_map(|base| rel_path(base, path)) 62 .find_map(|base| rel_path(base, path))
65 .filter(|path| !data.excluded_dirs.contains(path)) 63 .filter(|path| !data.excluded_dirs.contains(path))
66 .filter(|path| !data.is_excluded(path)) 64 .filter(|path| !data.is_excluded(path))
67 } 65 }
66
67 fn root(&self, root: VfsRoot) -> &RootData {
68 &self.roots[root.0 as usize]
69 }
68} 70}
69 71
70impl RootData { 72impl RootData {