@@ -33,6 +33,16 @@ pub(crate) enum PatternRefutability {
3333pub ( crate ) struct PathCompletionContext {
3434 /// If this is a call with () already there
3535 call_kind : Option < CallKind > ,
36+ /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
37+ pub ( super ) is_trivial_path : bool ,
38+ /// If not a trivial path, the prefix (qualifier).
39+ pub ( super ) path_qual : Option < ast:: Path > ,
40+ pub ( super ) is_path_type : bool ,
41+ pub ( super ) has_type_args : bool ,
42+ /// `true` if we are a statement or a last expr in the block.
43+ pub ( super ) can_be_stmt : bool ,
44+ /// `true` if we expect an expression at the cursor position.
45+ pub ( super ) is_expr : bool ,
3646}
3747
3848#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -83,16 +93,6 @@ pub(crate) struct CompletionContext<'a> {
8393 pub ( super ) path_context : Option < PathCompletionContext > ,
8494 /// FIXME: `ActiveParameter` is string-based, which is very very wrong
8595 pub ( super ) active_parameter : Option < ActiveParameter > ,
86- /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
87- pub ( super ) is_trivial_path : bool ,
88- /// If not a trivial path, the prefix (qualifier).
89- pub ( super ) path_qual : Option < ast:: Path > ,
90- /// `true` if we are a statement or a last expr in the block.
91- pub ( super ) can_be_stmt : bool ,
92- /// `true` if we expect an expression at the cursor position.
93- pub ( super ) is_expr : bool ,
94- pub ( super ) is_path_type : bool ,
95- pub ( super ) has_type_args : bool ,
9696 pub ( super ) locals : Vec < ( String , Local ) > ,
9797
9898 pub ( super ) previous_token : Option < SyntaxToken > ,
@@ -156,13 +156,7 @@ impl<'a> CompletionContext<'a> {
156156 is_label_ref : false ,
157157 is_param : false ,
158158 is_pat_or_const : None ,
159- is_trivial_path : false ,
160- path_qual : None ,
161- can_be_stmt : false ,
162- is_expr : false ,
163159 path_context : None ,
164- is_path_type : false ,
165- has_type_args : false ,
166160 previous_token : None ,
167161 in_loop_body : false ,
168162 completion_location : None ,
@@ -280,11 +274,6 @@ impl<'a> CompletionContext<'a> {
280274 matches ! ( self . completion_location, Some ( ImmediateLocation :: ItemList ) )
281275 }
282276
283- // fn expects_value(&self) -> bool {
284- pub ( crate ) fn expects_expression ( & self ) -> bool {
285- self . is_expr
286- }
287-
288277 pub ( crate ) fn has_block_expr_parent ( & self ) -> bool {
289278 matches ! ( self . completion_location, Some ( ImmediateLocation :: BlockExpr ) )
290279 }
@@ -321,10 +310,26 @@ impl<'a> CompletionContext<'a> {
321310 ) || self . attribute_under_caret . is_some ( )
322311 }
323312
313+ pub ( crate ) fn expects_expression ( & self ) -> bool {
314+ self . path_context . as_ref ( ) . map_or ( false , |it| it. is_expr )
315+ }
316+
324317 pub ( crate ) fn path_call_kind ( & self ) -> Option < CallKind > {
325318 self . path_context . as_ref ( ) . and_then ( |it| it. call_kind )
326319 }
327320
321+ pub ( crate ) fn is_trivial_path ( & self ) -> bool {
322+ self . path_context . as_ref ( ) . map_or ( false , |it| it. is_trivial_path )
323+ }
324+
325+ pub ( crate ) fn path_qual ( & self ) -> Option < & ast:: Path > {
326+ self . path_context . as_ref ( ) . and_then ( |it| it. path_qual . as_ref ( ) )
327+ }
328+
329+ pub ( crate ) fn can_be_stmt ( & self ) -> bool {
330+ self . path_context . as_ref ( ) . map_or ( false , |it| it. can_be_stmt )
331+ }
332+
328333 fn fill_impl_def ( & mut self ) {
329334 self . impl_def = self
330335 . sema
@@ -577,7 +582,15 @@ impl<'a> CompletionContext<'a> {
577582 } ;
578583
579584 if let Some ( segment) = ast:: PathSegment :: cast ( parent) {
580- let mut path_ctx = PathCompletionContext { call_kind : None } ;
585+ let path_ctx = self . path_context . get_or_insert ( PathCompletionContext {
586+ call_kind : None ,
587+ is_trivial_path : false ,
588+ path_qual : None ,
589+ has_type_args : false ,
590+ is_path_type : false ,
591+ can_be_stmt : false ,
592+ is_expr : false ,
593+ } ) ;
581594 let path = segment. parent_path ( ) ;
582595
583596 if let Some ( p) = path. syntax ( ) . parent ( ) {
@@ -590,13 +603,11 @@ impl<'a> CompletionContext<'a> {
590603 }
591604 } ;
592605 }
593- self . path_context = Some ( path_ctx) ;
594- dbg ! ( & self . path_context) ;
595- self . is_path_type = path. syntax ( ) . parent ( ) . and_then ( ast:: PathType :: cast) . is_some ( ) ;
596- self . has_type_args = segment. generic_arg_list ( ) . is_some ( ) ;
606+ path_ctx. is_path_type = path. syntax ( ) . parent ( ) . and_then ( ast:: PathType :: cast) . is_some ( ) ;
607+ path_ctx. has_type_args = segment. generic_arg_list ( ) . is_some ( ) ;
597608
598609 if let Some ( path) = path_or_use_tree_qualifier ( & path) {
599- self . path_qual = path
610+ path_ctx . path_qual = path
600611 . segment ( )
601612 . and_then ( |it| {
602613 find_node_with_range :: < ast:: PathSegment > (
@@ -614,11 +625,11 @@ impl<'a> CompletionContext<'a> {
614625 }
615626 }
616627
617- self . is_trivial_path = true ;
628+ path_ctx . is_trivial_path = true ;
618629
619630 // Find either enclosing expr statement (thing with `;`) or a
620631 // block. If block, check that we are the last expr.
621- self . can_be_stmt = name_ref
632+ path_ctx . can_be_stmt = name_ref
622633 . syntax ( )
623634 . ancestors ( )
624635 . find_map ( |node| {
@@ -634,7 +645,7 @@ impl<'a> CompletionContext<'a> {
634645 None
635646 } )
636647 . unwrap_or ( false ) ;
637- self . is_expr = path. syntax ( ) . parent ( ) . and_then ( ast:: PathExpr :: cast) . is_some ( ) ;
648+ path_ctx . is_expr = path. syntax ( ) . parent ( ) . and_then ( ast:: PathExpr :: cast) . is_some ( ) ;
638649 }
639650 }
640651}
0 commit comments