diff options
author | Florian Diebold <[email protected]> | 2018-12-24 19:32:39 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-25 14:16:42 +0000 |
commit | 4ff161852016c6c15954d6f30bd637834a2b2b68 (patch) | |
tree | 7ea2d34a8f58f5a242481e6d6294bef22546fcaf /crates/ra_hir/src/lib.rs | |
parent | b5b68f2094d49cacde6d7f0c49f521a0b25f34bd (diff) |
Do name resolution by namespace (types/values)
Diffstat (limited to 'crates/ra_hir/src/lib.rs')
-rw-r--r-- | crates/ra_hir/src/lib.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 7e9824de9..81526fe9c 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -41,7 +41,7 @@ use crate::{ | |||
41 | pub use self::{ | 41 | pub use self::{ |
42 | path::{Path, PathKind}, | 42 | path::{Path, PathKind}, |
43 | krate::Crate, | 43 | krate::Crate, |
44 | module::{Module, ModuleId, Problem, nameres::ItemMap, ModuleScope, Resolution}, | 44 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, |
45 | function::{Function, FnScopes}, | 45 | function::{Function, FnScopes}, |
46 | adt::{Struct, Enum}, | 46 | adt::{Struct, Enum}, |
47 | }; | 47 | }; |
@@ -61,6 +61,8 @@ pub(crate) enum DefKind { | |||
61 | Struct, | 61 | Struct, |
62 | Enum, | 62 | Enum, |
63 | Item, | 63 | Item, |
64 | |||
65 | StructCtor, | ||
64 | } | 66 | } |
65 | 67 | ||
66 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 68 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
@@ -72,18 +74,18 @@ pub struct DefLoc { | |||
72 | } | 74 | } |
73 | 75 | ||
74 | impl DefKind { | 76 | impl DefKind { |
75 | pub(crate) fn for_syntax_kind(kind: SyntaxKind) -> Option<DefKind> { | 77 | pub(crate) fn for_syntax_kind(kind: SyntaxKind) -> PerNs<DefKind> { |
76 | match kind { | 78 | match kind { |
77 | SyntaxKind::FN_DEF => Some(DefKind::Function), | 79 | SyntaxKind::FN_DEF => PerNs::values(DefKind::Function), |
78 | SyntaxKind::MODULE => Some(DefKind::Module), | 80 | SyntaxKind::MODULE => PerNs::types(DefKind::Module), |
81 | SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor), | ||
82 | SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum), | ||
79 | // These define items, but don't have their own DefKinds yet: | 83 | // These define items, but don't have their own DefKinds yet: |
80 | SyntaxKind::STRUCT_DEF => Some(DefKind::Struct), | 84 | SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Item), |
81 | SyntaxKind::ENUM_DEF => Some(DefKind::Enum), | 85 | SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Item), |
82 | SyntaxKind::TRAIT_DEF => Some(DefKind::Item), | 86 | SyntaxKind::CONST_DEF => PerNs::values(DefKind::Item), |
83 | SyntaxKind::TYPE_DEF => Some(DefKind::Item), | 87 | SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Item), |
84 | SyntaxKind::CONST_DEF => Some(DefKind::Item), | 88 | _ => PerNs::none(), |
85 | SyntaxKind::STATIC_DEF => Some(DefKind::Item), | ||
86 | _ => None, | ||
87 | } | 89 | } |
88 | } | 90 | } |
89 | } | 91 | } |
@@ -128,6 +130,7 @@ impl DefId { | |||
128 | let enum_def = Enum::new(self); | 130 | let enum_def = Enum::new(self); |
129 | Def::Enum(enum_def) | 131 | Def::Enum(enum_def) |
130 | } | 132 | } |
133 | DefKind::StructCtor => Def::Item, | ||
131 | DefKind::Item => Def::Item, | 134 | DefKind::Item => Def::Item, |
132 | }; | 135 | }; |
133 | Ok(res) | 136 | Ok(res) |