diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 6 |
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 { | |||
1064 | pub struct ImplBlock { | 1065 | pub struct ImplBlock { |
1065 | pub(crate) id: ImplId, | 1066 | pub(crate) id: ImplId, |
1066 | } | 1067 | } |
1068 | |||
1069 | /// For IDE only | ||
1070 | pub enum ScopeDef { | ||
1071 | ModuleDef(ModuleDef), | ||
1072 | MacroDef(MacroDef), | ||
1073 | GenericParam(u32), | ||
1074 | ImplSelfType(ImplBlock), | ||
1075 | AdtSelfType(Adt), | ||
1076 | Local(Local), | ||
1077 | Unknown, | ||
1078 | } | ||
1079 | |||
1080 | impl 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 | ||
424 | pub enum ScopeDef { | ||
425 | ModuleDef(ModuleDef), | ||
426 | MacroDef(MacroDef), | ||
427 | GenericParam(u32), | ||
428 | ImplSelfType(ImplBlock), | ||
429 | AdtSelfType(Adt), | ||
430 | Local(Local), | ||
431 | Unknown, | ||
432 | } | ||
433 | |||
434 | impl 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 | |||
446 | impl Scope { | 423 | impl 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 | ||
33 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { | 33 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { |