From d221ff4f9e0e270939a2944a2471bc3f027a674b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 00:19:55 +0200 Subject: Auto import macros --- crates/ra_hir/src/code_model.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index e91abf6f5..146e7820e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -139,6 +139,17 @@ impl ModuleDef { } } +impl From for ItemInNs { + fn from(module_def: ModuleDef) -> Self { + match module_def { + ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { + ItemInNs::Values(module_def.into()) + } + _ => ItemInNs::Types(module_def.into()), + } + } +} + pub use hir_def::{ attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, }; @@ -275,19 +286,9 @@ impl Module { pub fn find_use_path( self, db: &dyn HirDatabase, - item: ModuleDef, + item: ItemInNs, ) -> Option { - // FIXME expose namespace choice - hir_def::find_path::find_path(db.upcast(), determine_item_namespace(item), self.into()) - } -} - -fn determine_item_namespace(module_def: ModuleDef) -> ItemInNs { - match module_def { - ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { - ItemInNs::Values(module_def.into()) - } - _ => ItemInNs::Types(module_def.into()), + hir_def::find_path::find_path(db.upcast(), item, self.into()) } } @@ -759,6 +760,12 @@ impl MacroDef { } } +impl From for ItemInNs { + fn from(macro_def: MacroDef) -> Self { + ItemInNs::Macros(macro_def.into()) + } +} + /// Invariant: `inner.as_assoc_item(db).is_some()` /// We do not actively enforce this invariant. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -- cgit v1.2.3