diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index d66be34db..9f197bb58 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use arrayvec::ArrayVec; | 1 | use arrayvec::ArrayVec; |
2 | use ra_db::FileId; | 2 | use ra_db::FileId; |
3 | use ra_syntax::ast; | 3 | use ra_syntax::{ast, SmolStr}; |
4 | use relative_path::RelativePathBuf; | 4 | use relative_path::RelativePathBuf; |
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
@@ -508,11 +508,17 @@ where | |||
508 | } | 508 | } |
509 | .collect(&*items); | 509 | .collect(&*items); |
510 | } | 510 | } |
511 | // out of line module, resovle, parse and recurse | 511 | // out of line module, resolve, parse and recurse |
512 | raw::ModuleData::Declaration { name, ast_id } => { | 512 | raw::ModuleData::Declaration { name, ast_id, attr_path } => { |
513 | let ast_id = ast_id.with_file_id(self.file_id); | 513 | let ast_id = ast_id.with_file_id(self.file_id); |
514 | let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); | 514 | let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); |
515 | match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) { | 515 | match resolve_submodule( |
516 | self.def_collector.db, | ||
517 | self.file_id, | ||
518 | name, | ||
519 | is_root, | ||
520 | attr_path.as_ref(), | ||
521 | ) { | ||
516 | Ok(file_id) => { | 522 | Ok(file_id) => { |
517 | let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); | 523 | let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id)); |
518 | let raw_items = self.def_collector.db.raw_items(file_id.into()); | 524 | let raw_items = self.def_collector.db.raw_items(file_id.into()); |
@@ -626,6 +632,7 @@ fn resolve_submodule( | |||
626 | file_id: HirFileId, | 632 | file_id: HirFileId, |
627 | name: &Name, | 633 | name: &Name, |
628 | is_root: bool, | 634 | is_root: bool, |
635 | attr_path: Option<&SmolStr>, | ||
629 | ) -> Result<FileId, RelativePathBuf> { | 636 | ) -> Result<FileId, RelativePathBuf> { |
630 | // FIXME: handle submodules of inline modules properly | 637 | // FIXME: handle submodules of inline modules properly |
631 | let file_id = file_id.original_file(db); | 638 | let file_id = file_id.original_file(db); |
@@ -639,7 +646,13 @@ fn resolve_submodule( | |||
639 | let file_mod = dir_path.join(format!("{}.rs", name)); | 646 | let file_mod = dir_path.join(format!("{}.rs", name)); |
640 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); | 647 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); |
641 | let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name)); | 648 | let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name)); |
642 | let mut candidates = ArrayVec::<[_; 2]>::new(); | 649 | let mut candidates = ArrayVec::<[_; 3]>::new(); |
650 | let file_attr_mod = attr_path.map(|file_path| { | ||
651 | let file_attr_mod = dir_path.join(file_path.to_string()); | ||
652 | candidates.push(file_attr_mod.clone()); | ||
653 | |||
654 | file_attr_mod | ||
655 | }); | ||
643 | if is_dir_owner { | 656 | if is_dir_owner { |
644 | candidates.push(file_mod.clone()); | 657 | candidates.push(file_mod.clone()); |
645 | candidates.push(dir_mod); | 658 | candidates.push(dir_mod); |
@@ -651,7 +664,13 @@ fn resolve_submodule( | |||
651 | // FIXME: handle ambiguity | 664 | // FIXME: handle ambiguity |
652 | match points_to.next() { | 665 | match points_to.next() { |
653 | Some(file_id) => Ok(file_id), | 666 | Some(file_id) => Ok(file_id), |
654 | None => Err(if is_dir_owner { file_mod } else { file_dir_mod }), | 667 | None => { |
668 | if let Some(file_attr_mod) = file_attr_mod { | ||
669 | Err(file_attr_mod) | ||
670 | } else { | ||
671 | Err(if is_dir_owner { file_mod } else { file_dir_mod }) | ||
672 | } | ||
673 | } | ||
655 | } | 674 | } |
656 | } | 675 | } |
657 | 676 | ||