diff options
author | Aleksey Kladov <[email protected]> | 2019-11-11 14:36:27 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-11 14:36:27 +0000 |
commit | c5a18c44e5211282c22b9ca7aae8700ee8ca1817 (patch) | |
tree | 1b0f7c7b0f430d4174ca05e5464b3af98128bafe | |
parent | ff609cc49715571324b72d2bda60d56878466640 (diff) |
Introduce hir::GenericParam
Unlike existing hir::GenericParams, this is a global ID.
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/name_definition.rs | 5 |
4 files changed, 19 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 09c4e97fa..5a0bd0c19 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -23,7 +23,7 @@ use crate::{ | |||
23 | adt::VariantDef, | 23 | adt::VariantDef, |
24 | db::{AstDatabase, DefDatabase, HirDatabase}, | 24 | db::{AstDatabase, DefDatabase, HirDatabase}, |
25 | expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, | 25 | expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, |
26 | generics::HasGenericParams, | 26 | generics::{GenericDef, HasGenericParams}, |
27 | ids::{ | 27 | ids::{ |
28 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | 28 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, |
29 | TypeAliasId, | 29 | TypeAliasId, |
@@ -1121,3 +1121,9 @@ impl Local { | |||
1121 | src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) | 1121 | src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) |
1122 | } | 1122 | } |
1123 | } | 1123 | } |
1124 | |||
1125 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
1126 | pub struct GenericParam { | ||
1127 | pub(crate) parent: GenericDef, | ||
1128 | pub(crate) idx: u32, | ||
1129 | } | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 125c4b289..92d71b9e8 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -65,8 +65,8 @@ pub use crate::{ | |||
65 | docs::{DocDef, Docs, Documentation}, | 65 | docs::{DocDef, Docs, Documentation}, |
66 | src::{HasBodySource, HasSource}, | 66 | src::{HasBodySource, HasSource}, |
67 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 67 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
68 | EnumVariant, FieldSource, FnData, Function, HasBody, Local, MacroDef, Module, ModuleDef, | 68 | EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module, |
69 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 69 | ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
70 | }, | 70 | }, |
71 | expr::ExprScopes, | 71 | expr::ExprScopes, |
72 | from_source::FromSource, | 72 | from_source::FromSource, |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index c5fdf3bab..fe4211819 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -28,8 +28,8 @@ use crate::{ | |||
28 | ids::LocationCtx, | 28 | ids::LocationCtx, |
29 | resolve::{ScopeDef, TypeNs, ValueNs}, | 29 | resolve::{ScopeDef, TypeNs, ValueNs}, |
30 | ty::method_resolution::{self, implements_trait}, | 30 | ty::method_resolution::{self, implements_trait}, |
31 | AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, Local, | 31 | AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody, |
32 | MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, | 32 | HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | fn try_get_resolver_for_node( | 35 | fn try_get_resolver_for_node( |
@@ -107,7 +107,7 @@ pub enum PathResolution { | |||
107 | /// A local binding (only value namespace) | 107 | /// A local binding (only value namespace) |
108 | Local(Local), | 108 | Local(Local), |
109 | /// A generic parameter | 109 | /// A generic parameter |
110 | GenericParam(u32), | 110 | GenericParam(GenericParam), |
111 | SelfType(crate::ImplBlock), | 111 | SelfType(crate::ImplBlock), |
112 | Macro(MacroDef), | 112 | Macro(MacroDef), |
113 | AssocItem(crate::AssocItem), | 113 | AssocItem(crate::AssocItem), |
@@ -227,7 +227,10 @@ impl SourceAnalyzer { | |||
227 | ) -> Option<PathResolution> { | 227 | ) -> Option<PathResolution> { |
228 | let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { | 228 | let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { |
229 | TypeNs::SelfType(it) => PathResolution::SelfType(it), | 229 | TypeNs::SelfType(it) => PathResolution::SelfType(it), |
230 | TypeNs::GenericParam(it) => PathResolution::GenericParam(it), | 230 | TypeNs::GenericParam(idx) => PathResolution::GenericParam(GenericParam { |
231 | parent: self.resolver.generic_def().unwrap(), | ||
232 | idx, | ||
233 | }), | ||
231 | TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()), | 234 | TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()), |
232 | TypeNs::EnumVariant(it) => PathResolution::Def(it.into()), | 235 | TypeNs::EnumVariant(it) => PathResolution::Def(it.into()), |
233 | TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), | 236 | TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), |
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index 450f7ea9b..ccd75278a 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -4,7 +4,8 @@ | |||
4 | //! Note that the reference search is possible for not all of the classified items. | 4 | //! Note that the reference search is possible for not all of the classified items. |
5 | 5 | ||
6 | use hir::{ | 6 | use hir::{ |
7 | Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, | 7 | Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, |
8 | VariantDef, | ||
8 | }; | 9 | }; |
9 | use ra_syntax::{ast, ast::VisibilityOwner}; | 10 | use ra_syntax::{ast, ast::VisibilityOwner}; |
10 | 11 | ||
@@ -18,7 +19,7 @@ pub enum NameKind { | |||
18 | Def(ModuleDef), | 19 | Def(ModuleDef), |
19 | SelfType(Ty), | 20 | SelfType(Ty), |
20 | Local(Local), | 21 | Local(Local), |
21 | GenericParam(u32), | 22 | GenericParam(GenericParam), |
22 | } | 23 | } |
23 | 24 | ||
24 | #[derive(PartialEq, Eq)] | 25 | #[derive(PartialEq, Eq)] |