Skip to content

Commit 9863798

Browse files
Rename the method to avoid false promises
1 parent f4ee885 commit 9863798

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

crates/ide/src/completion/complete_mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
5252
.filter_map(|submodule_file| {
5353
let submodule_path = source_root.path_for_file(&submodule_file)?;
5454
let directory_with_submodule = submodule_path.parent()?;
55-
match submodule_path.file_name_and_extension()? {
55+
match submodule_path.name_and_extension()? {
5656
("lib", Some("rs")) | ("main", Some("rs")) => None,
5757
("mod", Some("rs")) => {
5858
if directory_with_submodule.parent()? == directory_to_look_for_submodules {
59-
match directory_with_submodule.file_name_and_extension()? {
59+
match directory_with_submodule.name_and_extension()? {
6060
(directory_name, None) => Some(directory_name.to_owned()),
6161
_ => None,
6262
}
@@ -93,7 +93,7 @@ fn directory_to_look_for_submodules(
9393
module_file_path: &VfsPath,
9494
) -> Option<VfsPath> {
9595
let directory_with_module_path = module_file_path.parent()?;
96-
let base_directory = match module_file_path.file_name_and_extension()? {
96+
let base_directory = match module_file_path.name_and_extension()? {
9797
("mod", Some("rs")) | ("lib", Some("rs")) | ("main", Some("rs")) => {
9898
Some(directory_with_module_path)
9999
}
@@ -103,8 +103,8 @@ fn directory_to_look_for_submodules(
103103
directory_with_module_path
104104
.parent()
105105
.as_ref()
106-
.and_then(|path| path.file_name_and_extension()),
107-
directory_with_module_path.file_name_and_extension(),
106+
.and_then(|path| path.name_and_extension()),
107+
directory_with_module_path.name_and_extension(),
108108
),
109109
(Some(("src", None)), Some(("bin", None)))
110110
) {

crates/vfs/src/vfs_path.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ impl VfsPath {
5757
}
5858
}
5959

60-
pub fn file_name_and_extension(&self) -> Option<(&str, Option<&str>)> {
60+
pub fn name_and_extension(&self) -> Option<(&str, Option<&str>)> {
6161
match &self.0 {
6262
VfsPathRepr::PathBuf(p) => Some((
6363
p.file_stem()?.to_str()?,
6464
p.extension().and_then(|extension| extension.to_str()),
6565
)),
66-
VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(),
66+
VfsPathRepr::VirtualPath(p) => p.name_and_extension(),
6767
}
6868
}
6969

@@ -287,9 +287,7 @@ impl VirtualPath {
287287
Some(res)
288288
}
289289

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>)> {
293291
let file_path = if self.0.ends_with('/') { &self.0[..&self.0.len() - 1] } else { &self.0 };
294292
let file_name = match file_path.rfind('/') {
295293
Some(position) => &file_path[position + 1..],
@@ -318,29 +316,29 @@ mod tests {
318316

319317
#[test]
320318
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);
322320
assert_eq!(
323-
VirtualPath("/directory".to_string()).file_name_and_extension(),
321+
VirtualPath("/directory".to_string()).name_and_extension(),
324322
Some(("directory", None))
325323
);
326324
assert_eq!(
327-
VirtualPath("/directory/".to_string()).file_name_and_extension(),
325+
VirtualPath("/directory/".to_string()).name_and_extension(),
328326
Some(("directory", None))
329327
);
330328
assert_eq!(
331-
VirtualPath("/directory/file".to_string()).file_name_and_extension(),
329+
VirtualPath("/directory/file".to_string()).name_and_extension(),
332330
Some(("file", None))
333331
);
334332
assert_eq!(
335-
VirtualPath("/directory/.file".to_string()).file_name_and_extension(),
333+
VirtualPath("/directory/.file".to_string()).name_and_extension(),
336334
Some((".file", None))
337335
);
338336
assert_eq!(
339-
VirtualPath("/directory/.file.rs".to_string()).file_name_and_extension(),
337+
VirtualPath("/directory/.file.rs".to_string()).name_and_extension(),
340338
Some((".file", Some("rs")))
341339
);
342340
assert_eq!(
343-
VirtualPath("/directory/file.rs".to_string()).file_name_and_extension(),
341+
VirtualPath("/directory/file.rs".to_string()).name_and_extension(),
344342
Some(("file", Some("rs")))
345343
);
346344
}

0 commit comments

Comments
 (0)