aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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}