@@ -29,6 +29,18 @@ pub(crate) enum PatternRefutability {
29
29
Irrefutable ,
30
30
}
31
31
32
+ #[ derive( Debug ) ]
33
+ pub ( crate ) struct PathCompletionContext {
34
+ /// If this is a call with () already there
35
+ call_kind : Option < CallKind > ,
36
+ }
37
+
38
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
39
+ pub ( crate ) enum CallKind {
40
+ Pat ,
41
+ Mac ,
42
+ Expr ,
43
+ }
32
44
/// `CompletionContext` is created early during completion to figure out, where
33
45
/// exactly is the cursor, syntax-wise.
34
46
#[ derive( Debug ) ]
@@ -68,6 +80,7 @@ pub(crate) struct CompletionContext<'a> {
68
80
pub ( super ) prev_sibling : Option < ImmediatePrevSibling > ,
69
81
pub ( super ) attribute_under_caret : Option < ast:: Attr > ,
70
82
83
+ pub ( super ) path_context : Option < PathCompletionContext > ,
71
84
/// FIXME: `ActiveParameter` is string-based, which is very very wrong
72
85
pub ( super ) active_parameter : Option < ActiveParameter > ,
73
86
/// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
@@ -78,12 +91,6 @@ pub(crate) struct CompletionContext<'a> {
78
91
pub ( super ) can_be_stmt : bool ,
79
92
/// `true` if we expect an expression at the cursor position.
80
93
pub ( super ) is_expr : bool ,
81
- /// If this is a call (method or function) in particular, i.e. the () are already there.
82
- pub ( super ) is_call : bool ,
83
- /// Like `is_call`, but for tuple patterns.
84
- pub ( super ) is_pattern_call : bool ,
85
- /// If this is a macro call, i.e. the () are already there.
86
- pub ( super ) is_macro_call : bool ,
87
94
pub ( super ) is_path_type : bool ,
88
95
pub ( super ) has_type_args : bool ,
89
96
pub ( super ) locals : Vec < ( String , Local ) > ,
@@ -153,9 +160,7 @@ impl<'a> CompletionContext<'a> {
153
160
path_qual : None ,
154
161
can_be_stmt : false ,
155
162
is_expr : false ,
156
- is_call : false ,
157
- is_pattern_call : false ,
158
- is_macro_call : false ,
163
+ path_context : None ,
159
164
is_path_type : false ,
160
165
has_type_args : false ,
161
166
previous_token : None ,
@@ -250,14 +255,14 @@ impl<'a> CompletionContext<'a> {
250
255
pub ( crate ) fn has_dot_receiver ( & self ) -> bool {
251
256
matches ! (
252
257
& self . completion_location,
253
- Some ( ImmediateLocation :: FieldAccess { receiver, .. } ) | Some ( ImmediateLocation :: MethodCall { receiver } )
258
+ Some ( ImmediateLocation :: FieldAccess { receiver, .. } ) | Some ( ImmediateLocation :: MethodCall { receiver, .. } )
254
259
if receiver. is_some( )
255
260
)
256
261
}
257
262
258
263
pub ( crate ) fn dot_receiver ( & self ) -> Option < & ast:: Expr > {
259
264
match & self . completion_location {
260
- Some ( ImmediateLocation :: MethodCall { receiver } )
265
+ Some ( ImmediateLocation :: MethodCall { receiver, .. } )
261
266
| Some ( ImmediateLocation :: FieldAccess { receiver, .. } ) => receiver. as_ref ( ) ,
262
267
_ => None ,
263
268
}
@@ -316,6 +321,10 @@ impl<'a> CompletionContext<'a> {
316
321
) || self . attribute_under_caret . is_some ( )
317
322
}
318
323
324
+ pub ( crate ) fn path_call_kind ( & self ) -> Option < CallKind > {
325
+ self . path_context . as_ref ( ) . and_then ( |it| it. call_kind )
326
+ }
327
+
319
328
fn fill_impl_def ( & mut self ) {
320
329
self . impl_def = self
321
330
. sema
@@ -568,17 +577,21 @@ impl<'a> CompletionContext<'a> {
568
577
} ;
569
578
570
579
if let Some ( segment) = ast:: PathSegment :: cast ( parent) {
580
+ let mut path_ctx = PathCompletionContext { call_kind : None } ;
571
581
let path = segment. parent_path ( ) ;
572
- self . is_call = path
573
- . syntax ( )
574
- . parent ( )
575
- . and_then ( ast:: PathExpr :: cast)
576
- . and_then ( |it| it. syntax ( ) . parent ( ) . and_then ( ast:: CallExpr :: cast) )
577
- . is_some ( ) ;
578
- self . is_macro_call = path. syntax ( ) . parent ( ) . and_then ( ast:: MacroCall :: cast) . is_some ( ) ;
579
- self . is_pattern_call =
580
- path. syntax ( ) . parent ( ) . and_then ( ast:: TupleStructPat :: cast) . is_some ( ) ;
581
582
583
+ if let Some ( p) = path. syntax ( ) . parent ( ) {
584
+ path_ctx. call_kind = match_ast ! {
585
+ match p {
586
+ ast:: PathExpr ( it) => it. syntax( ) . parent( ) . and_then( ast:: CallExpr :: cast) . map( |_| CallKind :: Expr ) ,
587
+ ast:: MacroCall ( _it) => Some ( CallKind :: Mac ) ,
588
+ ast:: TupleStructPat ( _it) => Some ( CallKind :: Pat ) ,
589
+ _ => None
590
+ }
591
+ } ;
592
+ }
593
+ self . path_context = Some ( path_ctx) ;
594
+ dbg ! ( & self . path_context) ;
582
595
self . is_path_type = path. syntax ( ) . parent ( ) . and_then ( ast:: PathType :: cast) . is_some ( ) ;
583
596
self . has_type_args = segment. generic_arg_list ( ) . is_some ( ) ;
584
597
@@ -623,8 +636,6 @@ impl<'a> CompletionContext<'a> {
623
636
. unwrap_or ( false ) ;
624
637
self . is_expr = path. syntax ( ) . parent ( ) . and_then ( ast:: PathExpr :: cast) . is_some ( ) ;
625
638
}
626
- self . is_call |=
627
- matches ! ( self . completion_location, Some ( ImmediateLocation :: MethodCall { .. } ) ) ;
628
639
}
629
640
}
630
641
0 commit comments