@@ -132,7 +132,7 @@ type labelled = {
132132type label = labelled option
133133type arg = {label : label ; exp : Parsetree .expression }
134134
135- let findExpApplyCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
135+ let findNamedArgCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
136136 ~(contextPath : Completable.contextPath ) ~posAfterFunExpr =
137137 let allNames =
138138 List. fold_right
@@ -211,7 +211,7 @@ let rec exprToContextPath (e : Parsetree.expression) =
211211 | Some contexPath -> Some (CPApply (contexPath, args |> List. map fst)))
212212 | _ -> None
213213
214- let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
214+ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
215215 let offset =
216216 match positionToOffset text posCursor with
217217 | Some offset -> offset
@@ -223,17 +223,18 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
223223 (line, max 0 col - offset + offsetNoWhite)
224224 in
225225 let posBeforeCursor = (fst posCursor, max 0 (snd posCursor - 1 )) in
226- let blankAfterCursor =
226+ let charBeforeCursor, blankAfterCursor =
227227 match positionToOffset text posCursor with
228228 | Some offset when offset > 0 -> (
229229 let charBeforeCursor = text.[offset - 1 ] in
230230 let charAtCursor =
231231 if offset < String. length text then text.[offset] else '\n'
232232 in
233233 match charAtCursor with
234- | ' ' | '\t' | '\r' | '\n' -> Some charBeforeCursor
235- | _ -> None )
236- | _ -> None
234+ | ' ' | '\t' | '\r' | '\n' ->
235+ (Some charBeforeCursor, Some charBeforeCursor)
236+ | _ -> (Some charBeforeCursor, None ))
237+ | _ -> (None , None )
237238 in
238239 let flattenLidCheckDot ?(jsx = true ) (lid : Longident.t Location.loc ) =
239240 (* Flatten an identifier keeping track of whether the current cursor
@@ -559,7 +560,13 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
559560 setPipeResult ~lhs ~id: " " |> ignore
560561 | Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "|." } } , [_; _]) ->
561562 ()
562- | Pexp_apply (funExpr , args ) ->
563+ | Pexp_apply (funExpr, args)
564+ when not
565+ (* Normally named arg completion fires when the cursor is right after the expression.
566+ E.g in foo(~<---there
567+ But it should not fire in foo(~a)<---there *)
568+ (Loc. end_ expr.pexp_loc = posCursor
569+ && charBeforeCursor = Some ')' ) ->
563570 let args = extractExpApplyArgs ~args in
564571 if debug then
565572 Printf. printf " Pexp_apply ...%s (%s)\n "
@@ -578,7 +585,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
578585 let expApplyCompletable =
579586 match exprToContextPath funExpr with
580587 | Some contextPath ->
581- findExpApplyCompletable ~context Path ~args
588+ findNamedArgCompletable ~context Path ~args
582589 ~end Pos:(Loc. end_ expr.pexp_loc) ~pos BeforeCursor
583590 ~pos AfterFunExpr:(Loc. end_ funExpr.pexp_loc)
584591 | None -> None
0 commit comments