From 8aa740dab46f138cacdf6391d46c87d6df810161 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 4 Sep 2020 02:25:00 +0300 Subject: Happy path implemented --- crates/base_db/src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'crates/base_db') diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 1bc4690c9..3e0b6637d 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -96,7 +96,7 @@ pub trait FileLoader { /// `#[path = "C://no/way"]` fn resolve_path(&self, anchor: FileId, path: &str) -> Option; fn relevant_crates(&self, file_id: FileId) -> Arc>; - fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)>; + fn possible_sudmobule_names(&self, module_file: FileId) -> Vec; } /// Database which stores all significant input facts: source code and project @@ -166,11 +166,11 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { self.0.source_root_crates(source_root) } - fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { + fn possible_sudmobule_names(&self, module_file: FileId) -> Vec { fn possible_sudmobules_opt( module_files: &FileSet, module_file: FileId, - ) -> Option> { + ) -> Option> { match module_files.file_name_and_extension(module_file)? { ("mod", Some("rs")) | ("lib", Some("rs")) => { module_files.list_files(module_file, None) @@ -181,8 +181,16 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { } } - possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file) + let module_files = &self.source_root(module_file).file_set; + possible_sudmobules_opt(module_files, module_file) .unwrap_or_default() + .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(), + }) + .collect() } } -- cgit v1.2.3