aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-21 11:21:26 +0000
committerAleksey Kladov <[email protected]>2019-11-21 11:21:26 +0000
commit1312c57d342730690a0181c53f82bb3e281114ff (patch)
tree9f6cb75c787d08f86d26cbd6204c30c5cb21948c /crates
parent061e6c77b5fdb63aa1cad63f1420a7fc810fa17d (diff)
Move ScopeDef
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs26
-rw-r--r--crates/ra_hir/src/lib.rs5
-rw-r--r--crates/ra_hir/src/resolve.rs25
-rw-r--r--crates/ra_hir/src/source_binder.rs6
4 files changed, 31 insertions, 31 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}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 31da74d2f..095d4964f 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -61,14 +61,13 @@ pub use crate::{
61 src::{HasBodySource, HasSource}, 61 src::{HasBodySource, HasSource},
62 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 62 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
63 EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local, 63 EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local,
64 MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, 64 MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait,
65 Union, VariantDef, 65 TypeAlias, Union, VariantDef,
66 }, 66 },
67 expr::ExprScopes, 67 expr::ExprScopes,
68 from_source::FromSource, 68 from_source::FromSource,
69 generics::GenericDef, 69 generics::GenericDef,
70 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, 70 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
71 resolve::ScopeDef,
72 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 71 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
73 ty::{ 72 ty::{
74 display::HirDisplay, 73 display::HirDisplay,
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index ed9fa0491..5e04ca9b6 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -19,7 +19,7 @@ use crate::{
19 code_model::Crate, 19 code_model::Crate,
20 db::HirDatabase, 20 db::HirDatabase,
21 expr::{ExprScopes, PatId, ScopeId}, 21 expr::{ExprScopes, PatId, ScopeId},
22 Adt, DefWithBody, GenericDef, ImplBlock, Local, MacroDef, ModuleDef, PerNs, 22 DefWithBody, GenericDef, Local, MacroDef, PerNs, ScopeDef,
23}; 23};
24 24
25#[derive(Debug, Clone, Default)] 25#[derive(Debug, Clone, Default)]
@@ -420,29 +420,6 @@ impl Resolver {
420 } 420 }
421} 421}
422 422
423/// For IDE only
424pub enum ScopeDef {
425 ModuleDef(ModuleDef),
426 MacroDef(MacroDef),
427 GenericParam(u32),
428 ImplSelfType(ImplBlock),
429 AdtSelfType(Adt),
430 Local(Local),
431 Unknown,
432}
433
434impl From<PerNs> for ScopeDef {
435 fn from(def: PerNs) -> Self {
436 def.take_types()
437 .or_else(|| def.take_values())
438 .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into()))
439 .or_else(|| {
440 def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into()))
441 })
442 .unwrap_or(ScopeDef::Unknown)
443 }
444}
445
446impl Scope { 423impl Scope {
447 fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) { 424 fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
448 match self { 425 match self {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 8e379498a..467e46d8c 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -23,11 +23,11 @@ use crate::{
23 db::HirDatabase, 23 db::HirDatabase,
24 expr::{BodySourceMap, ExprScopes, ScopeId}, 24 expr::{BodySourceMap, ExprScopes, ScopeId},
25 ids::LocationCtx, 25 ids::LocationCtx,
26 resolve::{resolver_for_scope, HasResolver, ScopeDef, TypeNs, ValueNs}, 26 resolve::{resolver_for_scope, HasResolver, TypeNs, ValueNs},
27 ty::method_resolution::{self, implements_trait}, 27 ty::method_resolution::{self, implements_trait},
28 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 28 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
29 GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, 29 GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, ScopeDef,
30 Struct, Trait, Ty, TypeAlias, 30 Static, Struct, Trait, Ty, TypeAlias,
31}; 31};
32 32
33fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 33fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {