aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/module_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/module_map.rs')
-rw-r--r--crates/libanalysis/src/module_map.rs51
1 files changed, 29 insertions, 22 deletions
diff --git a/crates/libanalysis/src/module_map.rs b/crates/libanalysis/src/module_map.rs
index 9acebd6e2..79b88cac2 100644
--- a/crates/libanalysis/src/module_map.rs
+++ b/crates/libanalysis/src/module_map.rs
@@ -244,31 +244,38 @@ impl Link {
244 self.points_to = Vec::new(); 244 self.points_to = Vec::new();
245 return; 245 return;
246 } 246 }
247 let (points_to, problem) = resolve_submodule(self.owner.0, &self.name(), file_resolver);
248 self.problem = problem;
249 self.points_to = points_to.into_iter().map(ModuleId).collect();
250 }
251}
247 252
248 let mod_name = file_resolver.file_stem(self.owner.0); 253pub(crate) fn resolve_submodule(file_id: FileId, name: &SmolStr, file_resolver: &FileResolverImp) -> (Vec<FileId>, Option<Problem>) {
249 let is_dir_owner = 254 let mod_name = file_resolver.file_stem(file_id);
250 mod_name == "mod" || mod_name == "lib" || mod_name == "main"; 255 let is_dir_owner =
256 mod_name == "mod" || mod_name == "lib" || mod_name == "main";
251 257
252 let file_mod = RelativePathBuf::from(format!("../{}.rs", self.name())); 258 let file_mod = RelativePathBuf::from(format!("../{}.rs", name));
253 let dir_mod = RelativePathBuf::from(format!("../{}/mod.rs", self.name())); 259 let dir_mod = RelativePathBuf::from(format!("../{}/mod.rs", name));
254 if is_dir_owner { 260 let points_to: Vec<FileId>;
255 self.points_to = [&file_mod, &dir_mod].iter() 261 let problem: Option<Problem>;
256 .filter_map(|path| file_resolver.resolve(self.owner.0, path)) 262 if is_dir_owner {
257 .map(ModuleId) 263 points_to = [&file_mod, &dir_mod].iter()
258 .collect(); 264 .filter_map(|path| file_resolver.resolve(file_id, path))
259 self.problem = if self.points_to.is_empty() { 265 .collect();
260 Some(Problem::UnresolvedModule { 266 problem = if points_to.is_empty() {
261 candidate: file_mod, 267 Some(Problem::UnresolvedModule {
262 })
263 } else {
264 None
265 }
266 } else {
267 self.points_to = Vec::new();
268 self.problem = Some(Problem::NotDirOwner {
269 move_to: RelativePathBuf::from(format!("../{}/mod.rs", mod_name)),
270 candidate: file_mod, 268 candidate: file_mod,
271 }); 269 })
270 } else {
271 None
272 } 272 }
273 } else {
274 points_to = Vec::new();
275 problem = Some(Problem::NotDirOwner {
276 move_to: RelativePathBuf::from(format!("../{}/mod.rs", mod_name)),
277 candidate: file_mod,
278 });
273 } 279 }
280 (points_to, problem)
274} 281}