Unnamed repository; edit this file 'description' to name the repository.
for filename, use localfilename first and then resort to other construction
| -rw-r--r-- | crates/load-cargo/src/lib.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index 5aa96582e9..023253f23f 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -563,14 +563,23 @@ impl ProcMacroExpander for Expander { let source_root_id = db.file_source_root(file).source_root_id(db); let source_root = db.source_root(source_root_id).source_root(db); - let name = source_root.path_for_file(&file).and_then(|path| { - path.name_and_extension().map(|(name, ext)| match ext { - Some(ext) => format!("{name}.{ext}"), - None => name.to_owned(), + let path = source_root.path_for_file(&file); + + let name = path + .and_then(|p| p.as_path()) + .and_then(|p| p.file_name()) + .map(|n| n.to_owned()) + .or_else(|| { + path.and_then(|p| { + p.name_and_extension().map(|(name, ext)| match ext { + Some(ext) => format!("{name}.{ext}"), + None => name.into(), + }) + }) }) - }); + .unwrap_or_default(); - Ok(SubResponse::FileNameResult { name: name.unwrap_or_default() }) + Ok(SubResponse::FileNameResult { name }) } }; match self.0.expand( |