@@ -60,6 +60,14 @@ pub(super) struct PatternContext {
60
60
pub ( super ) is_param : Option < ParamKind > ,
61
61
}
62
62
63
+ #[ derive( Debug ) ]
64
+ pub ( super ) enum LifetimeContext {
65
+ LifetimeParam ( Option < ast:: LifetimeParam > ) ,
66
+ Lifetime ,
67
+ LabelRef ,
68
+ LabelDef ,
69
+ }
70
+
63
71
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
64
72
pub ( crate ) enum CallKind {
65
73
Pat ,
@@ -96,16 +104,12 @@ pub(crate) struct CompletionContext<'a> {
96
104
pub ( super ) impl_def : Option < ast:: Impl > ,
97
105
pub ( super ) name_syntax : Option < ast:: NameLike > ,
98
106
99
- // potentially set if we are completing a lifetime
100
- pub ( super ) lifetime_param_syntax : Option < ast:: LifetimeParam > ,
101
- pub ( super ) lifetime_allowed : bool ,
102
- pub ( super ) is_label_ref : bool ,
103
-
104
107
pub ( super ) completion_location : Option < ImmediateLocation > ,
105
108
pub ( super ) prev_sibling : Option < ImmediatePrevSibling > ,
106
109
pub ( super ) attribute_under_caret : Option < ast:: Attr > ,
107
110
pub ( super ) previous_token : Option < SyntaxToken > ,
108
111
112
+ pub ( super ) lifetime_ctx : Option < LifetimeContext > ,
109
113
pub ( super ) pattern_ctx : Option < PatternContext > ,
110
114
pub ( super ) path_context : Option < PathCompletionContext > ,
111
115
pub ( super ) locals : Vec < ( String , Local ) > ,
@@ -161,9 +165,7 @@ impl<'a> CompletionContext<'a> {
161
165
function_def : None ,
162
166
impl_def : None ,
163
167
name_syntax : None ,
164
- lifetime_param_syntax : None ,
165
- lifetime_allowed : false ,
166
- is_label_ref : false ,
168
+ lifetime_ctx : None ,
167
169
pattern_ctx : None ,
168
170
completion_location : None ,
169
171
prev_sibling : None ,
@@ -294,8 +296,14 @@ impl<'a> CompletionContext<'a> {
294
296
self . previous_token . as_ref ( ) . map_or ( false , |tok| tok. kind ( ) == kind)
295
297
}
296
298
297
- pub ( crate ) fn expects_assoc_item ( & self ) -> bool {
298
- matches ! ( self . completion_location, Some ( ImmediateLocation :: Trait | ImmediateLocation :: Impl ) )
299
+ pub ( crate ) fn dot_receiver ( & self ) -> Option < & ast:: Expr > {
300
+ match & self . completion_location {
301
+ Some (
302
+ ImmediateLocation :: MethodCall { receiver, .. }
303
+ | ImmediateLocation :: FieldAccess { receiver, .. } ,
304
+ ) => receiver. as_ref ( ) ,
305
+ _ => None ,
306
+ }
299
307
}
300
308
301
309
pub ( crate ) fn has_dot_receiver ( & self ) -> bool {
@@ -306,14 +314,8 @@ impl<'a> CompletionContext<'a> {
306
314
)
307
315
}
308
316
309
- pub ( crate ) fn dot_receiver ( & self ) -> Option < & ast:: Expr > {
310
- match & self . completion_location {
311
- Some (
312
- ImmediateLocation :: MethodCall { receiver, .. }
313
- | ImmediateLocation :: FieldAccess { receiver, .. } ,
314
- ) => receiver. as_ref ( ) ,
315
- _ => None ,
316
- }
317
+ pub ( crate ) fn expects_assoc_item ( & self ) -> bool {
318
+ matches ! ( self . completion_location, Some ( ImmediateLocation :: Trait | ImmediateLocation :: Impl ) )
317
319
}
318
320
319
321
pub ( crate ) fn expects_non_trait_assoc_item ( & self ) -> bool {
@@ -676,19 +678,15 @@ impl<'a> CompletionContext<'a> {
676
678
return ;
677
679
}
678
680
679
- match_ast ! {
681
+ self . lifetime_ctx = Some ( match_ast ! {
680
682
match parent {
681
- ast:: LifetimeParam ( _it) => {
682
- self . lifetime_allowed = true ;
683
- self . lifetime_param_syntax =
684
- self . sema. find_node_at_offset_with_macros( original_file, offset) ;
685
- } ,
686
- ast:: BreakExpr ( _it) => self . is_label_ref = true ,
687
- ast:: ContinueExpr ( _it) => self . is_label_ref = true ,
688
- ast:: Label ( _it) => ( ) ,
689
- _ => self . lifetime_allowed = true ,
683
+ ast:: LifetimeParam ( _it) => LifetimeContext :: LifetimeParam ( self . sema. find_node_at_offset_with_macros( original_file, offset) ) ,
684
+ ast:: BreakExpr ( _it) => LifetimeContext :: LabelRef ,
685
+ ast:: ContinueExpr ( _it) => LifetimeContext :: LabelRef ,
686
+ ast:: Label ( _it) => LifetimeContext :: LabelDef ,
687
+ _ => LifetimeContext :: Lifetime ,
690
688
}
691
- }
689
+ } ) ;
692
690
}
693
691
}
694
692
0 commit comments