aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/collector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs63
1 files changed, 29 insertions, 34 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index c5b73cfbe..bc6bc5e7f 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -6,9 +6,9 @@ use ra_db::FileId;
6 6
7use crate::{ 7use crate::{
8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, 8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
9 DefDatabase, HirFileId, Name, Path, Problem, Crate, 9 DefDatabase, HirFileId, Name, Path, Crate,
10 KnownName, 10 KnownName,
11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw}, 11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw, DefDiagnostic},
12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, 12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId},
13}; 13};
14 14
@@ -405,25 +405,27 @@ where
405 raw::ModuleData::Declaration { name, source_item_id } => { 405 raw::ModuleData::Declaration { name, source_item_id } => {
406 let source_item_id = source_item_id.with_file_id(self.file_id); 406 let source_item_id = source_item_id.with_file_id(self.file_id);
407 let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); 407 let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none();
408 let (file_ids, problem) = 408 match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) {
409 resolve_submodule(self.def_collector.db, self.file_id, name, is_root); 409 Ok(file_id) => {
410 410 let module_id =
411 if let Some(problem) = problem { 411 self.push_child_module(name.clone(), source_item_id, Some(file_id));
412 self.def_collector.def_map.problems.add(source_item_id, problem) 412 let raw_items = self.def_collector.db.raw_items(file_id);
413 } 413 ModCollector {
414 414 def_collector: &mut *self.def_collector,
415 if let Some(&file_id) = file_ids.first() { 415 module_id,
416 let module_id = 416 file_id: file_id.into(),
417 self.push_child_module(name.clone(), source_item_id, Some(file_id)); 417 raw_items: &raw_items,
418 let raw_items = self.def_collector.db.raw_items(file_id); 418 }
419 ModCollector { 419 .collect(raw_items.items())
420 def_collector: &mut *self.def_collector,
421 module_id,
422 file_id: file_id.into(),
423 raw_items: &raw_items,
424 } 420 }
425 .collect(raw_items.items()) 421 Err(candidate) => self.def_collector.def_map.diagnostics.push(
426 } 422 DefDiagnostic::UnresolvedModule {
423 module: self.module_id,
424 declaration: source_item_id,
425 candidate,
426 },
427 ),
428 };
427 } 429 }
428 } 430 }
429 } 431 }
@@ -524,7 +526,7 @@ fn resolve_submodule(
524 file_id: HirFileId, 526 file_id: HirFileId,
525 name: &Name, 527 name: &Name,
526 is_root: bool, 528 is_root: bool,
527) -> (Vec<FileId>, Option<Problem>) { 529) -> Result<FileId, RelativePathBuf> {
528 // FIXME: handle submodules of inline modules properly 530 // FIXME: handle submodules of inline modules properly
529 let file_id = file_id.original_file(db); 531 let file_id = file_id.original_file(db);
530 let source_root_id = db.file_source_root(file_id); 532 let source_root_id = db.file_source_root(file_id);
@@ -545,17 +547,10 @@ fn resolve_submodule(
545 candidates.push(file_dir_mod.clone()); 547 candidates.push(file_dir_mod.clone());
546 }; 548 };
547 let sr = db.source_root(source_root_id); 549 let sr = db.source_root(source_root_id);
548 let points_to = candidates 550 let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).map(|&it| it);
549 .into_iter() 551 // FIXME: handle ambiguity
550 .filter_map(|path| sr.files.get(&path)) 552 match points_to.next() {
551 .map(|&it| it) 553 Some(file_id) => Ok(file_id),
552 .collect::<Vec<_>>(); 554 None => Err(if is_dir_owner { file_mod } else { file_dir_mod }),
553 let problem = if points_to.is_empty() { 555 }
554 Some(Problem::UnresolvedModule {
555 candidate: if is_dir_owner { file_mod } else { file_dir_mod },
556 })
557 } else {
558 None
559 };
560 (points_to, problem)
561} 556}