mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Auto import macros
This commit is contained in:
parent
f9494f1147
commit
d221ff4f9e
5 changed files with 46 additions and 34 deletions
|
@ -139,6 +139,17 @@ impl ModuleDef {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ModuleDef> 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<hir_def::path::ModPath> {
|
||||
// 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<MacroDef> 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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue