@@ -60,6 +60,12 @@ pub(crate) enum CallKind {
6060 Mac ,
6161 Expr ,
6262}
63+
64+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
65+ pub ( crate ) enum ParamKind {
66+ Function ,
67+ Closure ,
68+ }
6369/// `CompletionContext` is created early during completion to figure out, where
6470/// exactly is the cursor, syntax-wise.
6571#[ derive( Debug ) ]
@@ -91,7 +97,7 @@ pub(crate) struct CompletionContext<'a> {
9197
9298 // potentially set if we are completing a name
9399 pub ( super ) is_pat_or_const : Option < PatternRefutability > ,
94- pub ( super ) is_param : bool ,
100+ pub ( super ) is_param : Option < ParamKind > ,
95101
96102 pub ( super ) completion_location : Option < ImmediateLocation > ,
97103 pub ( super ) prev_sibling : Option < ImmediatePrevSibling > ,
@@ -158,7 +164,7 @@ impl<'a> CompletionContext<'a> {
158164 lifetime_allowed : false ,
159165 is_label_ref : false ,
160166 is_pat_or_const : None ,
161- is_param : false ,
167+ is_param : None ,
162168 completion_location : None ,
163169 prev_sibling : None ,
164170 attribute_under_caret : None ,
@@ -670,7 +676,17 @@ impl<'a> CompletionContext<'a> {
670676 self . fill_impl_def ( ) ;
671677 }
672678
673- self . is_param |= is_node :: < ast:: Param > ( name. syntax ( ) ) ;
679+ if let Some ( param) = name
680+ . syntax ( )
681+ . ancestors ( )
682+ . find_map ( ast:: Param :: cast)
683+ . filter ( |it| it. syntax ( ) . text_range ( ) == name. syntax ( ) . text_range ( ) )
684+ {
685+ let is_closure_param =
686+ param. syntax ( ) . ancestors ( ) . nth ( 2 ) . and_then ( ast:: ClosureExpr :: cast) . is_some ( ) ;
687+ self . is_param =
688+ Some ( if is_closure_param { ParamKind :: Closure } else { ParamKind :: Function } ) ;
689+ }
674690 }
675691
676692 fn classify_name_ref ( & mut self , original_file : & SyntaxNode , name_ref : ast:: NameRef ) {
@@ -774,13 +790,6 @@ fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Op
774790 syntax. covering_element ( range) . ancestors ( ) . find_map ( N :: cast)
775791}
776792
777- fn is_node < N : AstNode > ( node : & SyntaxNode ) -> bool {
778- match node. ancestors ( ) . find_map ( N :: cast) {
779- None => false ,
780- Some ( n) => n. syntax ( ) . text_range ( ) == node. text_range ( ) ,
781- }
782- }
783-
784793fn path_or_use_tree_qualifier ( path : & ast:: Path ) -> Option < ( ast:: Path , bool ) > {
785794 if let Some ( qual) = path. qualifier ( ) {
786795 return Some ( ( qual, false ) ) ;
0 commit comments