aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index c4935c0d7..39b01d510 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -10,6 +10,7 @@ use hir_def::{
10 adt::VariantData, 10 adt::VariantData,
11 body::scope::ExprScopes, 11 body::scope::ExprScopes,
12 builtin_type::BuiltinType, 12 builtin_type::BuiltinType,
13 nameres::per_ns::PerNs,
13 traits::TraitData, 14 traits::TraitData,
14 type_ref::{Mutability, TypeRef}, 15 type_ref::{Mutability, TypeRef},
15 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, 16 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
@@ -32,7 +33,7 @@ use crate::{
32 }, 33 },
33 resolve::{HasResolver, TypeNs}, 34 resolve::{HasResolver, TypeNs},
34 ty::{InferenceResult, Namespace, TraitRef}, 35 ty::{InferenceResult, Namespace, TraitRef},
35 Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, 36 Either, HasSource, ImportId, Name, Source, Ty,
36}; 37};
37 38
38/// hir::Crate describes a single crate. It's the main interface with which 39/// hir::Crate describes a single crate. It's the main interface with which
@@ -1064,3 +1065,26 @@ pub struct GenericParam {
1064pub struct ImplBlock { 1065pub struct ImplBlock {
1065 pub(crate) id: ImplId, 1066 pub(crate) id: ImplId,
1066} 1067}
1068
1069/// For IDE only
1070pub enum ScopeDef {
1071 ModuleDef(ModuleDef),
1072 MacroDef(MacroDef),
1073 GenericParam(u32),
1074 ImplSelfType(ImplBlock),
1075 AdtSelfType(Adt),
1076 Local(Local),
1077 Unknown,
1078}
1079
1080impl From<PerNs> for ScopeDef {
1081 fn from(def: PerNs) -> Self {
1082 def.take_types()
1083 .or_else(|| def.take_values())
1084 .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into()))
1085 .or_else(|| {
1086 def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into()))
1087 })
1088 .unwrap_or(ScopeDef::Unknown)
1089 }
1090}