diff options
Diffstat (limited to 'crates/vfs')
-rw-r--r-- | crates/vfs/src/file_set.rs | 17 | ||||
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 13 |
2 files changed, 17 insertions, 13 deletions
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index 3f49f31e5..956cffb29 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs | |||
@@ -34,22 +34,27 @@ impl FileSet { | |||
34 | &self, | 34 | &self, |
35 | anchor: FileId, | 35 | anchor: FileId, |
36 | anchor_relative_path: Option<&str>, | 36 | anchor_relative_path: Option<&str>, |
37 | ) -> Option<Vec<(FileId, String)>> { | 37 | ) -> Option<Vec<FileId>> { |
38 | let anchor_directory = { | 38 | let anchor_directory = { |
39 | let path = self.paths[&anchor].clone(); | 39 | let path = self.paths[&anchor].clone(); |
40 | match anchor_relative_path { | 40 | match anchor_relative_path { |
41 | Some(anchor_relative_path) => path.join(anchor_relative_path), | 41 | Some(anchor_relative_path) => path.join(anchor_relative_path), |
42 | None => path.join("../"), | 42 | None => path.parent(), |
43 | } | 43 | } |
44 | }?; | 44 | }?; |
45 | 45 | ||
46 | Some( | 46 | Some( |
47 | self.paths | 47 | self.paths |
48 | .iter() | 48 | .iter() |
49 | .filter(|(_, path)| path.starts_with(&anchor_directory)) | 49 | .filter_map(|(&file_id, path)| { |
50 | // TODO kb need to ensure that no / exists after the anchor_directory | 50 | if path.parent()? == anchor_directory |
51 | .filter(|(_, path)| path.ends_with(".rs")) | 51 | && matches!(path.file_name_and_extension(), Some((_, Some("rs")))) |
52 | .map(|(&file_id, path)| (file_id, path.to_string())) | 52 | { |
53 | Some(file_id) | ||
54 | } else { | ||
55 | None | ||
56 | } | ||
57 | }) | ||
53 | .collect(), | 58 | .collect(), |
54 | ) | 59 | ) |
55 | } | 60 | } |
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index f2d07038b..9a3690a89 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -48,10 +48,12 @@ impl VfsPath { | |||
48 | (VfsPathRepr::VirtualPath(_), _) => false, | 48 | (VfsPathRepr::VirtualPath(_), _) => false, |
49 | } | 49 | } |
50 | } | 50 | } |
51 | pub fn ends_with(&self, suffix: &str) -> bool { | 51 | pub fn parent(&self) -> Option<VfsPath> { |
52 | match &self.0 { | 52 | let mut parent = self.clone(); |
53 | VfsPathRepr::PathBuf(p) => p.ends_with(suffix), | 53 | if parent.pop() { |
54 | VfsPathRepr::VirtualPath(p) => p.ends_with(suffix), | 54 | Some(parent) |
55 | } else { | ||
56 | None | ||
55 | } | 57 | } |
56 | } | 58 | } |
57 | 59 | ||
@@ -265,9 +267,6 @@ impl VirtualPath { | |||
265 | fn starts_with(&self, other: &VirtualPath) -> bool { | 267 | fn starts_with(&self, other: &VirtualPath) -> bool { |
266 | self.0.starts_with(&other.0) | 268 | self.0.starts_with(&other.0) |
267 | } | 269 | } |
268 | fn ends_with(&self, suffix: &str) -> bool { | ||
269 | self.0.ends_with(suffix) | ||
270 | } | ||
271 | fn pop(&mut self) -> bool { | 270 | fn pop(&mut self) -> bool { |
272 | let pos = match self.0.rfind('/') { | 271 | let pos = match self.0.rfind('/') { |
273 | Some(pos) => pos, | 272 | Some(pos) => pos, |