aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs/src')
-rw-r--r--crates/ra_vfs/src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index 6b4eb6842..2d861f832 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -94,6 +94,7 @@ impl Roots {
94 let mut roots = Arena::default(); 94 let mut roots = Arena::default();
95 // A hack to make nesting work. 95 // A hack to make nesting work.
96 paths.sort_by_key(|it| Reverse(it.as_os_str().len())); 96 paths.sort_by_key(|it| Reverse(it.as_os_str().len()));
97 paths.dedup();
97 for (i, path) in paths.iter().enumerate() { 98 for (i, path) in paths.iter().enumerate() {
98 let nested_roots = paths[..i] 99 let nested_roots = paths[..i]
99 .iter() 100 .iter()
@@ -161,6 +162,13 @@ impl Vfs {
161 self.roots[root].root.clone() 162 self.roots[root].root.clone()
162 } 163 }
163 164
165 pub fn path2root(&self, path: &Path) -> Option<VfsRoot> {
166 match self.find_root(path) {
167 Some((root, _path, _file)) => Some(root),
168 _ => None,
169 }
170 }
171
164 pub fn path2file(&self, path: &Path) -> Option<VfsFile> { 172 pub fn path2file(&self, path: &Path) -> Option<VfsFile> {
165 if let Some((_root, _path, Some(file))) = self.find_root(path) { 173 if let Some((_root, _path, Some(file))) = self.find_root(path) {
166 return Some(file); 174 return Some(file);
@@ -181,6 +189,10 @@ impl Vfs {
181 None 189 None
182 } 190 }
183 191
192 pub fn num_roots(&self) -> usize {
193 self.roots.len()
194 }
195
184 pub fn load(&mut self, path: &Path) -> Option<VfsFile> { 196 pub fn load(&mut self, path: &Path) -> Option<VfsFile> {
185 if let Some((root, rel_path, file)) = self.find_root(path) { 197 if let Some((root, rel_path, file)) = self.find_root(path) {
186 return if let Some(file) = file { 198 return if let Some(file) = file {