@@ -57,13 +57,13 @@ impl VfsPath {
57
57
}
58
58
}
59
59
60
- pub fn file_name_and_extension ( & self ) -> Option < ( & str , Option < & str > ) > {
60
+ pub fn name_and_extension ( & self ) -> Option < ( & str , Option < & str > ) > {
61
61
match & self . 0 {
62
62
VfsPathRepr :: PathBuf ( p) => Some ( (
63
63
p. file_stem ( ) ?. to_str ( ) ?,
64
64
p. extension ( ) . and_then ( |extension| extension. to_str ( ) ) ,
65
65
) ) ,
66
- VfsPathRepr :: VirtualPath ( p) => p. file_name_and_extension ( ) ,
66
+ VfsPathRepr :: VirtualPath ( p) => p. name_and_extension ( ) ,
67
67
}
68
68
}
69
69
@@ -287,9 +287,7 @@ impl VirtualPath {
287
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
292
- pub fn file_name_and_extension ( & self ) -> Option < ( & str , Option < & str > ) > {
290
+ pub fn name_and_extension ( & self ) -> Option < ( & str , Option < & str > ) > {
293
291
let file_path = if self . 0 . ends_with ( '/' ) { & self . 0 [ ..& self . 0 . len ( ) - 1 ] } else { & self . 0 } ;
294
292
let file_name = match file_path. rfind ( '/' ) {
295
293
Some ( position) => & file_path[ position + 1 ..] ,
@@ -318,29 +316,29 @@ mod tests {
318
316
319
317
#[ test]
320
318
fn virtual_path_extensions ( ) {
321
- assert_eq ! ( VirtualPath ( "/" . to_string( ) ) . file_name_and_extension ( ) , None ) ;
319
+ assert_eq ! ( VirtualPath ( "/" . to_string( ) ) . name_and_extension ( ) , None ) ;
322
320
assert_eq ! (
323
- VirtualPath ( "/directory" . to_string( ) ) . file_name_and_extension ( ) ,
321
+ VirtualPath ( "/directory" . to_string( ) ) . name_and_extension ( ) ,
324
322
Some ( ( "directory" , None ) )
325
323
) ;
326
324
assert_eq ! (
327
- VirtualPath ( "/directory/" . to_string( ) ) . file_name_and_extension ( ) ,
325
+ VirtualPath ( "/directory/" . to_string( ) ) . name_and_extension ( ) ,
328
326
Some ( ( "directory" , None ) )
329
327
) ;
330
328
assert_eq ! (
331
- VirtualPath ( "/directory/file" . to_string( ) ) . file_name_and_extension ( ) ,
329
+ VirtualPath ( "/directory/file" . to_string( ) ) . name_and_extension ( ) ,
332
330
Some ( ( "file" , None ) )
333
331
) ;
334
332
assert_eq ! (
335
- VirtualPath ( "/directory/.file" . to_string( ) ) . file_name_and_extension ( ) ,
333
+ VirtualPath ( "/directory/.file" . to_string( ) ) . name_and_extension ( ) ,
336
334
Some ( ( ".file" , None ) )
337
335
) ;
338
336
assert_eq ! (
339
- VirtualPath ( "/directory/.file.rs" . to_string( ) ) . file_name_and_extension ( ) ,
337
+ VirtualPath ( "/directory/.file.rs" . to_string( ) ) . name_and_extension ( ) ,
340
338
Some ( ( ".file" , Some ( "rs" ) ) )
341
339
) ;
342
340
assert_eq ! (
343
- VirtualPath ( "/directory/file.rs" . to_string( ) ) . file_name_and_extension ( ) ,
341
+ VirtualPath ( "/directory/file.rs" . to_string( ) ) . name_and_extension ( ) ,
344
342
Some ( ( "file" , Some ( "rs" ) ) )
345
343
) ;
346
344
}
0 commit comments