aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/src/roots.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs/src/roots.rs')
-rw-r--r--crates/ra_vfs/src/roots.rs20
1 files changed, 11 insertions, 9 deletions
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 {