6
6
// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
7
7
8
8
use hir:: {
9
- Adt , AssocItem , HasSource , ImplBlock , InFile , Local , MacroDef , Module , ModuleDef , SourceBinder ,
9
+ Adt , HasSource , ImplBlock , InFile , Local , MacroDef , Module , ModuleDef , SourceBinder ,
10
10
StructField , TypeParam , VariantDef ,
11
11
} ;
12
12
use ra_prof:: profile;
@@ -20,9 +20,8 @@ use crate::RootDatabase;
20
20
#[ derive( Debug , PartialEq , Eq ) ]
21
21
pub enum NameKind {
22
22
Macro ( MacroDef ) ,
23
- Field ( StructField ) ,
24
- AssocItem ( AssocItem ) ,
25
- Def ( ModuleDef ) ,
23
+ StructField ( StructField ) ,
24
+ ModuleDef ( ModuleDef ) ,
26
25
SelfType ( ImplBlock ) ,
27
26
Local ( Local ) ,
28
27
TypeParam ( TypeParam ) ,
@@ -92,29 +91,17 @@ pub fn classify_name(
92
91
ast:: FnDef ( it) => {
93
92
let src = name. with_value( it) ;
94
93
let def: hir:: Function = sb. to_def( src) ?;
95
- if parent. parent( ) . and_then( ast:: ItemList :: cast) . map_or( false , |it| it. syntax( ) . parent( ) . and_then( ast:: Module :: cast) . is_none( ) ) {
96
- Some ( from_assoc_item( sb. db, def. into( ) ) )
97
- } else {
98
- Some ( from_module_def( sb. db, def. into( ) , None ) )
99
- }
94
+ Some ( from_module_def( sb. db, def. into( ) , None ) )
100
95
} ,
101
96
ast:: ConstDef ( it) => {
102
97
let src = name. with_value( it) ;
103
98
let def: hir:: Const = sb. to_def( src) ?;
104
- if parent. parent( ) . and_then( ast:: ItemList :: cast) . is_some( ) {
105
- Some ( from_assoc_item( sb. db, def. into( ) ) )
106
- } else {
107
- Some ( from_module_def( sb. db, def. into( ) , None ) )
108
- }
99
+ Some ( from_module_def( sb. db, def. into( ) , None ) )
109
100
} ,
110
101
ast:: TypeAliasDef ( it) => {
111
102
let src = name. with_value( it) ;
112
103
let def: hir:: TypeAlias = sb. to_def( src) ?;
113
- if parent. parent( ) . and_then( ast:: ItemList :: cast) . is_some( ) {
114
- Some ( from_assoc_item( sb. db, def. into( ) ) )
115
- } else {
116
- Some ( from_module_def( sb. db, def. into( ) , None ) )
117
- }
104
+ Some ( from_module_def( sb. db, def. into( ) , None ) )
118
105
} ,
119
106
ast:: MacroCall ( it) => {
120
107
let src = name. with_value( it) ;
@@ -142,19 +129,8 @@ pub fn classify_name(
142
129
}
143
130
}
144
131
145
- pub fn from_assoc_item ( db : & RootDatabase , item : AssocItem ) -> NameDefinition {
146
- let container = item. module ( db) ;
147
- let visibility = match item {
148
- AssocItem :: Function ( f) => f. source ( db) . value . visibility ( ) ,
149
- AssocItem :: Const ( c) => c. source ( db) . value . visibility ( ) ,
150
- AssocItem :: TypeAlias ( a) => a. source ( db) . value . visibility ( ) ,
151
- } ;
152
- let kind = NameKind :: AssocItem ( item) ;
153
- NameDefinition { kind, container, visibility }
154
- }
155
-
156
132
pub fn from_struct_field ( db : & RootDatabase , field : StructField ) -> NameDefinition {
157
- let kind = NameKind :: Field ( field) ;
133
+ let kind = NameKind :: StructField ( field) ;
158
134
let parent = field. parent_def ( db) ;
159
135
let container = parent. module ( db) ;
160
136
let visibility = match parent {
@@ -170,7 +146,7 @@ pub fn from_module_def(
170
146
def : ModuleDef ,
171
147
module : Option < Module > ,
172
148
) -> NameDefinition {
173
- let kind = NameKind :: Def ( def) ;
149
+ let kind = NameKind :: ModuleDef ( def) ;
174
150
let ( container, visibility) = match def {
175
151
ModuleDef :: Module ( it) => {
176
152
let container = it. parent ( db) . or_else ( || Some ( it) ) . unwrap ( ) ;
0 commit comments