@@ -39,13 +39,7 @@ pub(crate) enum TypeAnnotation {
39
39
/// from which file the nodes are.
40
40
#[ derive( Clone , Debug , PartialEq , Eq ) ]
41
41
pub ( crate ) enum ImmediateLocation {
42
- Impl ,
43
- Trait ,
44
- TupleField ,
45
42
RefExpr ,
46
- IdentPat ,
47
- StmtList ,
48
- ItemList ,
49
43
TypeBound ,
50
44
/// Original file ast node
51
45
TypeAnnotation ( TypeAnnotation ) ,
@@ -140,30 +134,14 @@ pub(crate) fn determine_location(
140
134
_ => parent,
141
135
} ,
142
136
// SourceFile
143
- None => {
144
- return match node. kind ( ) {
145
- MACRO_ITEMS | SOURCE_FILE => Some ( ImmediateLocation :: ItemList ) ,
146
- _ => None ,
147
- }
148
- }
137
+ None => return None ,
149
138
} ;
150
139
151
140
let res = match_ast ! {
152
141
match parent {
153
- ast:: IdentPat ( _) => ImmediateLocation :: IdentPat ,
154
- ast:: StmtList ( _) => ImmediateLocation :: StmtList ,
155
- ast:: SourceFile ( _) => ImmediateLocation :: ItemList ,
156
- ast:: ItemList ( _) => ImmediateLocation :: ItemList ,
157
142
ast:: RefExpr ( _) => ImmediateLocation :: RefExpr ,
158
- ast:: TupleField ( _) => ImmediateLocation :: TupleField ,
159
- ast:: TupleFieldList ( _) => ImmediateLocation :: TupleField ,
160
143
ast:: TypeBound ( _) => ImmediateLocation :: TypeBound ,
161
144
ast:: TypeBoundList ( _) => ImmediateLocation :: TypeBound ,
162
- ast:: AssocItemList ( it) => match it. syntax( ) . parent( ) . map( |it| it. kind( ) ) {
163
- Some ( IMPL ) => ImmediateLocation :: Impl ,
164
- Some ( TRAIT ) => ImmediateLocation :: Trait ,
165
- _ => return None ,
166
- } ,
167
145
ast:: GenericArgList ( _) => sema
168
146
. find_node_at_offset_with_macros( original_file, offset)
169
147
. map( ImmediateLocation :: GenericArgList ) ?,
@@ -359,56 +337,11 @@ mod tests {
359
337
} ) ;
360
338
}
361
339
362
- #[ test]
363
- fn test_trait_loc ( ) {
364
- check_location ( r"trait A { f$0 }" , ImmediateLocation :: Trait ) ;
365
- check_location ( r"trait A { #[attr] f$0 }" , ImmediateLocation :: Trait ) ;
366
- check_location ( r"trait A { f$0 fn f() {} }" , ImmediateLocation :: Trait ) ;
367
- check_location ( r"trait A { fn f() {} f$0 }" , ImmediateLocation :: Trait ) ;
368
- check_location ( r"trait A$0 {}" , None ) ;
369
- check_location ( r"trait A { fn f$0 }" , None ) ;
370
- }
371
-
372
- #[ test]
373
- fn test_impl_loc ( ) {
374
- check_location ( r"impl A { f$0 }" , ImmediateLocation :: Impl ) ;
375
- check_location ( r"impl A { #[attr] f$0 }" , ImmediateLocation :: Impl ) ;
376
- check_location ( r"impl A { f$0 fn f() {} }" , ImmediateLocation :: Impl ) ;
377
- check_location ( r"impl A { fn f() {} f$0 }" , ImmediateLocation :: Impl ) ;
378
- check_location ( r"impl A$0 {}" , None ) ;
379
- check_location ( r"impl A { fn f$0 }" , None ) ;
380
- }
381
-
382
- #[ test]
383
- fn test_block_expr_loc ( ) {
384
- check_location ( r"fn my_fn() { let a = 2; f$0 }" , ImmediateLocation :: StmtList ) ;
385
- check_location ( r"fn my_fn() { f$0 f }" , ImmediateLocation :: StmtList ) ;
386
- }
387
-
388
- #[ test]
389
- fn test_ident_pat_loc ( ) {
390
- check_location ( r"fn my_fn(m$0) {}" , ImmediateLocation :: IdentPat ) ;
391
- check_location ( r"fn my_fn() { let m$0 }" , ImmediateLocation :: IdentPat ) ;
392
- check_location ( r"fn my_fn(&m$0) {}" , ImmediateLocation :: IdentPat ) ;
393
- check_location ( r"fn my_fn() { let &m$0 }" , ImmediateLocation :: IdentPat ) ;
394
- }
395
-
396
340
#[ test]
397
341
fn test_ref_expr_loc ( ) {
398
342
check_location ( r"fn my_fn() { let x = &m$0 foo; }" , ImmediateLocation :: RefExpr ) ;
399
343
}
400
344
401
- #[ test]
402
- fn test_item_list_loc ( ) {
403
- check_location ( r"i$0" , ImmediateLocation :: ItemList ) ;
404
- check_location ( r"#[attr] i$0" , ImmediateLocation :: ItemList ) ;
405
- check_location ( r"fn f() {} i$0" , ImmediateLocation :: ItemList ) ;
406
- check_location ( r"mod foo { f$0 }" , ImmediateLocation :: ItemList ) ;
407
- check_location ( r"mod foo { #[attr] f$0 }" , ImmediateLocation :: ItemList ) ;
408
- check_location ( r"mod foo { fn f() {} f$0 }" , ImmediateLocation :: ItemList ) ;
409
- check_location ( r"mod foo$0 {}" , None ) ;
410
- }
411
-
412
345
#[ test]
413
346
fn test_impl_prev_sibling ( ) {
414
347
check_prev_sibling ( r"impl A w$0 " , ImmediatePrevSibling :: ImplDefType ) ;
0 commit comments