diff options
Diffstat (limited to 'crates/ra_vfs/src/roots.rs')
-rw-r--r-- | crates/ra_vfs/src/roots.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/crates/ra_vfs/src/roots.rs b/crates/ra_vfs/src/roots.rs index 5e2776a35..4503458ee 100644 --- a/crates/ra_vfs/src/roots.rs +++ b/crates/ra_vfs/src/roots.rs | |||
@@ -1,16 +1,13 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | iter, | 2 | iter, |
3 | sync::Arc, | ||
4 | path::{Path, PathBuf}, | 3 | path::{Path, PathBuf}, |
5 | }; | 4 | }; |
6 | 5 | ||
7 | use relative_path::{ RelativePath, RelativePathBuf}; | 6 | use relative_path::{ RelativePath, RelativePathBuf}; |
8 | use ra_arena::{impl_arena_id, Arena, RawId}; | ||
9 | 7 | ||
10 | /// VfsRoot identifies a watched directory on the file system. | 8 | /// VfsRoot identifies a watched directory on the file system. |
11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 9 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | pub struct VfsRoot(pub RawId); | 10 | pub struct VfsRoot(pub u32); |
13 | impl_arena_id!(VfsRoot); | ||
14 | 11 | ||
15 | /// Describes the contents of a single source root. | 12 | /// Describes the contents of a single source root. |
16 | /// | 13 | /// |
@@ -25,12 +22,12 @@ struct RootData { | |||
25 | } | 22 | } |
26 | 23 | ||
27 | pub(crate) struct Roots { | 24 | pub(crate) struct Roots { |
28 | roots: Arena<VfsRoot, Arc<RootData>>, | 25 | roots: Vec<RootData>, |
29 | } | 26 | } |
30 | 27 | ||
31 | impl Roots { | 28 | impl Roots { |
32 | pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots { | 29 | pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots { |
33 | let mut roots = Arena::default(); | 30 | let mut roots = Vec::new(); |
34 | // A hack to make nesting work. | 31 | // A hack to make nesting work. |
35 | 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())); |
36 | paths.dedup(); | 33 | paths.dedup(); |
@@ -38,9 +35,7 @@ impl Roots { | |||
38 | let nested_roots = | 35 | let nested_roots = |
39 | 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<_>>(); |
40 | 37 | ||
41 | let config = Arc::new(RootData::new(path.clone(), nested_roots)); | 38 | roots.push(RootData::new(path.clone(), nested_roots)); |
42 | |||
43 | roots.alloc(config.clone()); | ||
44 | } | 39 | } |
45 | Roots { roots } | 40 | Roots { roots } |
46 | } | 41 | } |
@@ -54,20 +49,24 @@ impl Roots { | |||
54 | self.roots.len() | 49 | self.roots.len() |
55 | } | 50 | } |
56 | 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 { |
57 | self.roots.iter().map(|(id, _)| id) | 52 | (0..self.roots.len()).into_iter().map(|idx| VfsRoot(idx as u32)) |
58 | } | 53 | } |
59 | pub(crate) fn path(&self, root: VfsRoot) -> &Path { | 54 | pub(crate) fn path(&self, root: VfsRoot) -> &Path { |
60 | self.roots[root].path.as_path() | 55 | self.root(root).path.as_path() |
61 | } | 56 | } |
62 | /// 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. |
63 | pub(crate) fn contains(&self, root: VfsRoot, path: &Path) -> Option<RelativePathBuf> { | 58 | pub(crate) fn contains(&self, root: VfsRoot, path: &Path) -> Option<RelativePathBuf> { |
64 | let data = &self.roots[root]; | 59 | let data = self.root(root); |
65 | iter::once(&data.path) | 60 | iter::once(&data.path) |
66 | .chain(data.canonical_path.as_ref().into_iter()) | 61 | .chain(data.canonical_path.as_ref().into_iter()) |
67 | .find_map(|base| rel_path(base, path)) | 62 | .find_map(|base| rel_path(base, path)) |
68 | .filter(|path| !data.excluded_dirs.contains(path)) | 63 | .filter(|path| !data.excluded_dirs.contains(path)) |
69 | .filter(|path| !data.is_excluded(path)) | 64 | .filter(|path| !data.is_excluded(path)) |
70 | } | 65 | } |
66 | |||
67 | fn root(&self, root: VfsRoot) -> &RootData { | ||
68 | &self.roots[root.0 as usize] | ||
69 | } | ||
71 | } | 70 | } |
72 | 71 | ||
73 | impl RootData { | 72 | impl RootData { |