@@ -132,7 +132,7 @@ type labelled = {
132
132
type label = labelled option
133
133
type arg = {label : label ; exp : Parsetree .expression }
134
134
135
- let findExpApplyCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
135
+ let findNamedArgCompletable ~(args : arg list ) ~endPos ~posBeforeCursor
136
136
~(contextPath : Completable.contextPath ) ~posAfterFunExpr =
137
137
let allNames =
138
138
List. fold_right
@@ -211,7 +211,7 @@ let rec exprToContextPath (e : Parsetree.expression) =
211
211
| Some contexPath -> Some (CPApply (contexPath, args |> List. map fst)))
212
212
| _ -> None
213
213
214
- let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
214
+ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
215
215
let offset =
216
216
match positionToOffset text posCursor with
217
217
| Some offset -> offset
@@ -223,17 +223,18 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
223
223
(line, max 0 col - offset + offsetNoWhite)
224
224
in
225
225
let posBeforeCursor = (fst posCursor, max 0 (snd posCursor - 1 )) in
226
- let blankAfterCursor =
226
+ let charBeforeCursor, blankAfterCursor =
227
227
match positionToOffset text posCursor with
228
228
| Some offset when offset > 0 -> (
229
229
let charBeforeCursor = text.[offset - 1 ] in
230
230
let charAtCursor =
231
231
if offset < String. length text then text.[offset] else '\n'
232
232
in
233
233
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 )
237
238
in
238
239
let flattenLidCheckDot ?(jsx = true ) (lid : Longident.t Location.loc ) =
239
240
(* Flatten an identifier keeping track of whether the current cursor
@@ -559,7 +560,13 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
559
560
setPipeResult ~lhs ~id: " " |> ignore
560
561
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "|." } } , [_; _]) ->
561
562
()
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 ')' ) ->
563
570
let args = extractExpApplyArgs ~args in
564
571
if debug then
565
572
Printf. printf " Pexp_apply ...%s (%s)\n "
@@ -578,7 +585,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
578
585
let expApplyCompletable =
579
586
match exprToContextPath funExpr with
580
587
| Some contextPath ->
581
- findExpApplyCompletable ~context Path ~args
588
+ findNamedArgCompletable ~context Path ~args
582
589
~end Pos:(Loc. end_ expr.pexp_loc) ~pos BeforeCursor
583
590
~pos AfterFunExpr:(Loc. end_ funExpr.pexp_loc)
584
591
| None -> None
0 commit comments