aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-09-04 13:05:56 +0100
committerKirill Bulatov <[email protected]>2020-09-09 23:42:20 +0100
commit897a4c702e3d6fa9156ea0bc34af9d397fae3440 (patch)
treebb0f1acb80c6eb214394c1a7481355dccf4a789f
parentd163f9f114c8180bec6285ad9962fabbf3af5b18 (diff)
Implement file name & extension retrieval method for VirtualPath
-rw-r--r--crates/vfs/src/vfs_path.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs
index 9a3690a89..113c2e4e6 100644
--- a/crates/vfs/src/vfs_path.rs
+++ b/crates/vfs/src/vfs_path.rs
@@ -287,8 +287,26 @@ impl VirtualPath {
287 Some(res) 287 Some(res)
288 } 288 }
289 289
290 // FIXME: Currently VirtualPath does is unable to distinguish a directory from a file
291 // hence this method will return `Some("directory_name", None)` for a directory
290 pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> { 292 pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> {
291 // TODO kb check if is a file 293 let file_name = match self.0.rfind('/') {
292 Some(("test_mod_1", Some("rs"))) 294 Some(position) => &self.0[position + 1..],
295 None => &self.0,
296 };
297
298 if file_name.is_empty() {
299 None
300 } else {
301 let mut file_stem_and_extension = file_name.rsplitn(2, '.');
302 let extension = file_stem_and_extension.next();
303 let file_stem = file_stem_and_extension.next();
304
305 match (file_stem, extension) {
306 (None, None) => None,
307 (None, Some(_)) | (Some(""), Some(_)) => Some((file_name, None)),
308 (Some(file_stem), extension) => Some((file_stem, extension)),
309 }
310 }
293 } 311 }
294} 312}