diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eaf8884cc7..0f485493f7 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -54,11 +54,12 @@ use hir_def::{ per_ns::PerNs, resolver::{HasResolver, Resolver}, type_ref::TypesSourceMap, - AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId, CrateRootModuleId, - DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, GenericParamId, - HasModule, ImplId, InTypeConstId, ItemContainerId, LifetimeParamId, LocalFieldId, Lookup, - MacroExpander, ModuleId, StaticId, StructId, SyntheticSyntax, TraitAliasId, TraitId, TupleId, - TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId, + AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId, + CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FunctionId, + GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId, + LifetimeParamId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, + SyntheticSyntax, TraitAliasId, TraitId, TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, + UnionId, }; use hir_expand::{ attrs::collect_attrs, proc_macro::ProcMacroKind, AstId, MacroCallKind, RenderedExpandError, @@ -127,7 +128,7 @@ pub use { ImportPathConfig, // FIXME: This is here since some queries take it as input that are used // outside of hir. - {AdtId, MacroId, ModuleDefId}, + ModuleDefId, }, hir_expand::{ attrs::{Attr, AttrId}, @@ -3000,6 +3001,10 @@ impl Macro { matches!(self.id, MacroId::MacroRulesId(id) if db.macro_rules_data(id).macro_export) } + pub fn is_proc_macro(self) -> bool { + matches!(self.id, MacroId::ProcMacroId(_)) + } + pub fn kind(&self, db: &dyn HirDatabase) -> MacroKind { match self.id { MacroId::Macro2Id(it) => match it.lookup(db.upcast()).expander { diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index b3105e6524..3a29232d33 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -260,23 +260,23 @@ impl From for SymbolKind { } } -impl From for SymbolKind { - fn from(it: hir::ModuleDefId) -> Self { +impl From for SymbolKind { + fn from(it: hir::ModuleDef) -> Self { match it { - hir::ModuleDefId::ConstId(..) => SymbolKind::Const, - hir::ModuleDefId::EnumVariantId(..) => SymbolKind::Variant, - hir::ModuleDefId::FunctionId(..) => SymbolKind::Function, - hir::ModuleDefId::MacroId(hir::MacroId::ProcMacroId(..)) => SymbolKind::ProcMacro, - hir::ModuleDefId::MacroId(..) => SymbolKind::Macro, - hir::ModuleDefId::ModuleId(..) => SymbolKind::Module, - hir::ModuleDefId::StaticId(..) => SymbolKind::Static, - hir::ModuleDefId::AdtId(hir::AdtId::StructId(..)) => SymbolKind::Struct, - hir::ModuleDefId::AdtId(hir::AdtId::EnumId(..)) => SymbolKind::Enum, - hir::ModuleDefId::AdtId(hir::AdtId::UnionId(..)) => SymbolKind::Union, - hir::ModuleDefId::TraitId(..) => SymbolKind::Trait, - hir::ModuleDefId::TraitAliasId(..) => SymbolKind::TraitAlias, - hir::ModuleDefId::TypeAliasId(..) => SymbolKind::TypeAlias, - hir::ModuleDefId::BuiltinType(..) => SymbolKind::TypeAlias, + hir::ModuleDef::Const(..) => SymbolKind::Const, + hir::ModuleDef::Variant(..) => SymbolKind::Variant, + hir::ModuleDef::Function(..) => SymbolKind::Function, + hir::ModuleDef::Macro(mac) if mac.is_proc_macro() => SymbolKind::ProcMacro, + hir::ModuleDef::Macro(..) => SymbolKind::Macro, + hir::ModuleDef::Module(..) => SymbolKind::Module, + hir::ModuleDef::Static(..) => SymbolKind::Static, + hir::ModuleDef::Adt(hir::Adt::Struct(..)) => SymbolKind::Struct, + hir::ModuleDef::Adt(hir::Adt::Enum(..)) => SymbolKind::Enum, + hir::ModuleDef::Adt(hir::Adt::Union(..)) => SymbolKind::Union, + hir::ModuleDef::Trait(..) => SymbolKind::Trait, + hir::ModuleDef::TraitAlias(..) => SymbolKind::TraitAlias, + hir::ModuleDef::TypeAlias(..) => SymbolKind::TypeAlias, + hir::ModuleDef::BuiltinType(..) => SymbolKind::TypeAlias, } } } diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs index 9259243db8..9230d64d64 100644 --- a/crates/ide/src/navigation_target.rs +++ b/crates/ide/src/navigation_target.rs @@ -195,7 +195,7 @@ impl TryToNav for FileSymbol { |it| it.display_no_db(edition).to_smolstr(), ), alias: self.is_alias.then(|| self.name.clone()), - kind: Some(hir::ModuleDefId::from(self.def).into()), + kind: Some(self.def.into()), full_range, focus_range, container_name: self.container_name.clone(),