diff options
author | Aleksey Kladov <[email protected]> | 2019-11-23 08:14:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-23 08:14:40 +0000 |
commit | 552ba868afc8f72202ac834d07bbeb330aca007d (patch) | |
tree | cd57fc21ce442e84bdc41241a70ece9995d826af /crates/ra_hir/src/code_model.rs | |
parent | 81bfbd26bef1a63ccbeba33430e6b07a53c8e7d9 (diff) |
Move attrs query to hir_def
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9f8c6c4a5..496b4ee8a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | pub(crate) mod src; | 3 | pub(crate) mod src; |
4 | pub(crate) mod docs; | 4 | pub(crate) mod docs; |
5 | pub(crate) mod attrs; | ||
6 | 5 | ||
7 | use std::sync::Arc; | 6 | use std::sync::Arc; |
8 | 7 | ||
@@ -13,8 +12,8 @@ use hir_def::{ | |||
13 | nameres::per_ns::PerNs, | 12 | nameres::per_ns::PerNs, |
14 | resolver::{HasResolver, TypeNs}, | 13 | resolver::{HasResolver, TypeNs}, |
15 | type_ref::TypeRef, | 14 | type_ref::TypeRef, |
16 | ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, | 15 | AdtId, ContainerId, CrateModuleId, EnumVariantId, HasModule, ImplId, LocalEnumVariantId, |
17 | ModuleId, UnionId, | 16 | LocalStructFieldId, Lookup, ModuleId, StructFieldId, UnionId, |
18 | }; | 17 | }; |
19 | use hir_expand::{ | 18 | use hir_expand::{ |
20 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
@@ -110,7 +109,7 @@ impl_froms!( | |||
110 | BuiltinType | 109 | BuiltinType |
111 | ); | 110 | ); |
112 | 111 | ||
113 | pub use hir_def::ModuleSource; | 112 | pub use hir_def::{attr::Attrs, ModuleSource}; |
114 | 113 | ||
115 | impl Module { | 114 | impl Module { |
116 | pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { | 115 | pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { |
@@ -991,3 +990,52 @@ impl From<PerNs> for ScopeDef { | |||
991 | .unwrap_or(ScopeDef::Unknown) | 990 | .unwrap_or(ScopeDef::Unknown) |
992 | } | 991 | } |
993 | } | 992 | } |
993 | |||
994 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
995 | pub enum AttrDef { | ||
996 | Module(Module), | ||
997 | StructField(StructField), | ||
998 | Adt(Adt), | ||
999 | Function(Function), | ||
1000 | EnumVariant(EnumVariant), | ||
1001 | Static(Static), | ||
1002 | Const(Const), | ||
1003 | Trait(Trait), | ||
1004 | TypeAlias(TypeAlias), | ||
1005 | MacroDef(MacroDef), | ||
1006 | } | ||
1007 | |||
1008 | impl_froms!( | ||
1009 | AttrDef: Module, | ||
1010 | StructField, | ||
1011 | Adt(Struct, Enum, Union), | ||
1012 | EnumVariant, | ||
1013 | Static, | ||
1014 | Const, | ||
1015 | Function, | ||
1016 | Trait, | ||
1017 | TypeAlias, | ||
1018 | MacroDef | ||
1019 | ); | ||
1020 | |||
1021 | pub trait HasAttrs { | ||
1022 | fn attrs(self, db: &impl DefDatabase) -> Attrs; | ||
1023 | } | ||
1024 | |||
1025 | impl<T: Into<AttrDef>> HasAttrs for T { | ||
1026 | fn attrs(self, db: &impl DefDatabase) -> Attrs { | ||
1027 | let def = self.into(); | ||
1028 | match def { | ||
1029 | AttrDef::Module(it) => db.attrs(it.id.into()), | ||
1030 | AttrDef::StructField(it) => db.attrs(StructFieldId::from(it).into()), | ||
1031 | AttrDef::Adt(it) => db.attrs(AdtId::from(it).into()), | ||
1032 | AttrDef::Function(it) => db.attrs(it.id.into()), | ||
1033 | AttrDef::EnumVariant(it) => db.attrs(EnumVariantId::from(it).into()), | ||
1034 | AttrDef::Static(it) => db.attrs(it.id.into()), | ||
1035 | AttrDef::Const(it) => db.attrs(it.id.into()), | ||
1036 | AttrDef::Trait(it) => db.attrs(it.id.into()), | ||
1037 | AttrDef::TypeAlias(it) => db.attrs(it.id.into()), | ||
1038 | AttrDef::MacroDef(it) => db.attrs(it.id.into()), | ||
1039 | } | ||
1040 | } | ||
1041 | } | ||