diff options
author | Kirill Bulatov <[email protected]> | 2020-09-03 21:18:23 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-09-09 23:42:20 +0100 |
commit | 17870a3e2c39770a99f9ab5ce090abbe1dc334d2 (patch) | |
tree | 85e98d57518fd2735820e9b70f16a7e2ab54d082 /crates/base_db/src | |
parent | 4bed588001a1d6cd5c83a3eefc6ef77c439de40b (diff) |
Better API
Diffstat (limited to 'crates/base_db/src')
-rw-r--r-- | crates/base_db/src/lib.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 71e85c6ac..37a8432bd 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs | |||
@@ -96,7 +96,7 @@ pub trait FileLoader { | |||
96 | /// `#[path = "C://no/way"]` | 96 | /// `#[path = "C://no/way"]` |
97 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>; | 97 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>; |
98 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; | 98 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; |
99 | fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)>; | 99 | fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)>; |
100 | } | 100 | } |
101 | 101 | ||
102 | /// Database which stores all significant input facts: source code and project | 102 | /// Database which stores all significant input facts: source code and project |
@@ -166,8 +166,25 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> { | |||
166 | self.0.source_root_crates(source_root) | 166 | self.0.source_root_crates(source_root) |
167 | } | 167 | } |
168 | 168 | ||
169 | fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { | 169 | fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { |
170 | self.source_root(anchor).file_set.list_some_random_files_todo(anchor) | 170 | fn possible_sudmobules_opt( |
171 | module_files: &FileSet, | ||
172 | module_file: FileId, | ||
173 | ) -> Option<Vec<(FileId, String)>> { | ||
174 | // TODO kb resolve path thinks that the input is a file... | ||
175 | let directory_with_module_file = module_files.resolve_path(module_file, "/../")?; | ||
176 | let directory_with_applicable_modules = | ||
177 | match module_files.file_name_and_extension(module_file)? { | ||
178 | ("mod", "rs") | ("lib", "rs") => Some(directory_with_module_file), | ||
179 | (directory_with_module_name, "rs") => module_files | ||
180 | .resolve_path(directory_with_module_file, directory_with_module_name), | ||
181 | _ => None, | ||
182 | }?; | ||
183 | Some(module_files.list_files(directory_with_applicable_modules)) | ||
184 | } | ||
185 | |||
186 | possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file) | ||
187 | .unwrap_or_default() | ||
171 | } | 188 | } |
172 | } | 189 | } |
173 | 190 | ||