aboutsummaryrefslogtreecommitdiff
path: root/crates/base_db
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-09-04 11:33:07 +0100
committerKirill Bulatov <[email protected]>2020-09-09 23:42:20 +0100
commitd163f9f114c8180bec6285ad9962fabbf3af5b18 (patch)
treeb88940186b9539465a70ea20503cf969b645cc04 /crates/base_db
parent8aa740dab46f138cacdf6391d46c87d6df810161 (diff)
Small refactoring
Diffstat (limited to 'crates/base_db')
-rw-r--r--crates/base_db/src/lib.rs36
1 files changed, 15 insertions, 21 deletions
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<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
167 } 167 }
168 168
169 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> { 169 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
170 fn possible_sudmobules_opt(
171 module_files: &FileSet,
172 module_file: FileId,
173 ) -> Option<Vec<FileId>> {
174 match module_files.file_name_and_extension(module_file)? {
175 ("mod", Some("rs")) | ("lib", Some("rs")) => {
176 module_files.list_files(module_file, None)
177 }
178 (directory_with_module_name, Some("rs")) => module_files
179 .list_files(module_file, Some(&format!("../{}/", directory_with_module_name))),
180 _ => None,
181 }
182 }
183
184 let module_files = &self.source_root(module_file).file_set; 170 let module_files = &self.source_root(module_file).file_set;
185 possible_sudmobules_opt(module_files, module_file) 171 let possible_submodule_files = match module_files.file_name_and_extension(module_file) {
186 .unwrap_or_default() 172 Some(("mod", Some("rs"))) | Some(("lib", Some("rs"))) => {
173 module_files.list_files_with_extensions(module_file, None)
174 }
175 Some((directory_with_module_name, Some("rs"))) => module_files
176 .list_files_with_extensions(
177 module_file,
178 Some(&format!("../{}/", directory_with_module_name)),
179 ),
180 _ => Vec::new(),
181 };
182
183 possible_submodule_files
187 .into_iter() 184 .into_iter()
188 .filter_map(|submodule_file| module_files.file_name_and_extension(submodule_file)) 185 .filter(|(_, extension)| extension == &Some("rs"))
189 .map(|(file_name, extension)| match extension { 186 .map(|(file_name, _)| file_name.to_owned())
190 Some(extension) => format!("{}.{}", file_name, extension),
191 None => file_name.to_owned(),
192 })
193 .collect() 187 .collect()
194 } 188 }
195} 189}