diff options
Diffstat (limited to 'crates/vfs/src/vfs_path.rs')
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 7b965bb4c..f2d07038b 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -48,13 +48,19 @@ impl VfsPath { | |||
48 | (VfsPathRepr::VirtualPath(_), _) => false, | 48 | (VfsPathRepr::VirtualPath(_), _) => false, |
49 | } | 49 | } |
50 | } | 50 | } |
51 | pub fn ends_with(&self, suffix: &str) -> bool { | ||
52 | match &self.0 { | ||
53 | VfsPathRepr::PathBuf(p) => p.ends_with(suffix), | ||
54 | VfsPathRepr::VirtualPath(p) => p.ends_with(suffix), | ||
55 | } | ||
56 | } | ||
51 | 57 | ||
52 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | 58 | pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> { |
53 | match &self.0 { | 59 | match &self.0 { |
54 | VfsPathRepr::PathBuf(p) => p | 60 | VfsPathRepr::PathBuf(p) => Some(( |
55 | .file_stem() | 61 | p.file_stem()?.to_str()?, |
56 | .zip(p.extension()) | 62 | p.extension().and_then(|extension| extension.to_str()), |
57 | .and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))), | 63 | )), |
58 | VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(), | 64 | VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(), |
59 | } | 65 | } |
60 | } | 66 | } |
@@ -259,6 +265,9 @@ impl VirtualPath { | |||
259 | fn starts_with(&self, other: &VirtualPath) -> bool { | 265 | fn starts_with(&self, other: &VirtualPath) -> bool { |
260 | self.0.starts_with(&other.0) | 266 | self.0.starts_with(&other.0) |
261 | } | 267 | } |
268 | fn ends_with(&self, suffix: &str) -> bool { | ||
269 | self.0.ends_with(suffix) | ||
270 | } | ||
262 | fn pop(&mut self) -> bool { | 271 | fn pop(&mut self) -> bool { |
263 | let pos = match self.0.rfind('/') { | 272 | let pos = match self.0.rfind('/') { |
264 | Some(pos) => pos, | 273 | Some(pos) => pos, |
@@ -279,8 +288,8 @@ impl VirtualPath { | |||
279 | Some(res) | 288 | Some(res) |
280 | } | 289 | } |
281 | 290 | ||
282 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | 291 | pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> { |
283 | // TODO kb check if is a file | 292 | // TODO kb check if is a file |
284 | Some(("test_mod_1", "rs")) | 293 | Some(("test_mod_1", Some("rs"))) |
285 | } | 294 | } |
286 | } | 295 | } |