From d163f9f114c8180bec6285ad9962fabbf3af5b18 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 4 Sep 2020 13:33:07 +0300 Subject: Small refactoring --- crates/base_db/src/lib.rs | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'crates/base_db/src') diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 3e0b6637d..55ef9fc24 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -167,29 +167,23 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { } fn possible_sudmobule_names(&self, module_file: FileId) -> Vec { - fn possible_sudmobules_opt( - module_files: &FileSet, - module_file: FileId, - ) -> Option> { - match module_files.file_name_and_extension(module_file)? { - ("mod", Some("rs")) | ("lib", Some("rs")) => { - module_files.list_files(module_file, None) - } - (directory_with_module_name, Some("rs")) => module_files - .list_files(module_file, Some(&format!("../{}/", directory_with_module_name))), - _ => None, - } - } - let module_files = &self.source_root(module_file).file_set; - possible_sudmobules_opt(module_files, module_file) - .unwrap_or_default() + let possible_submodule_files = match module_files.file_name_and_extension(module_file) { + Some(("mod", Some("rs"))) | Some(("lib", Some("rs"))) => { + module_files.list_files_with_extensions(module_file, None) + } + Some((directory_with_module_name, Some("rs"))) => module_files + .list_files_with_extensions( + module_file, + Some(&format!("../{}/", directory_with_module_name)), + ), + _ => Vec::new(), + }; + + possible_submodule_files .into_iter() - .filter_map(|submodule_file| module_files.file_name_and_extension(submodule_file)) - .map(|(file_name, extension)| match extension { - Some(extension) => format!("{}.{}", file_name, extension), - None => file_name.to_owned(), - }) + .filter(|(_, extension)| extension == &Some("rs")) + .map(|(file_name, _)| file_name.to_owned()) .collect() } } -- cgit v1.2.3