From 0de71f7bc9482c9d1ef7e9d36ec5d6c5fd378781 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 4 Sep 2020 01:32:06 +0300 Subject: Properly use FileSet API --- crates/vfs/src/vfs_path.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'crates/vfs/src/vfs_path.rs') 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 { (VfsPathRepr::VirtualPath(_), _) => false, } } + pub fn ends_with(&self, suffix: &str) -> bool { + match &self.0 { + VfsPathRepr::PathBuf(p) => p.ends_with(suffix), + VfsPathRepr::VirtualPath(p) => p.ends_with(suffix), + } + } - pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { + pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> { match &self.0 { - VfsPathRepr::PathBuf(p) => p - .file_stem() - .zip(p.extension()) - .and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))), + VfsPathRepr::PathBuf(p) => Some(( + p.file_stem()?.to_str()?, + p.extension().and_then(|extension| extension.to_str()), + )), VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(), } } @@ -259,6 +265,9 @@ impl VirtualPath { fn starts_with(&self, other: &VirtualPath) -> bool { self.0.starts_with(&other.0) } + fn ends_with(&self, suffix: &str) -> bool { + self.0.ends_with(suffix) + } fn pop(&mut self) -> bool { let pos = match self.0.rfind('/') { Some(pos) => pos, @@ -279,8 +288,8 @@ impl VirtualPath { Some(res) } - pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { + pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> { // TODO kb check if is a file - Some(("test_mod_1", "rs")) + Some(("test_mod_1", Some("rs"))) } } -- cgit v1.2.3