@@ -155,7 +155,11 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor
155
155
" [findArgCompletables] skipping completion in fn call because \
156
156
arg had empty loc" ;
157
157
None
158
- | _ ->
158
+ | _
159
+ when firstCharBeforeCursorNoWhite = Some '('
160
+ || firstCharBeforeCursorNoWhite = Some ',' ->
161
+ (* Checks to ensure that completing for empty unlabelled arg makes
162
+ sense by checking what's left of the cursor. *)
159
163
if Debug. verbose () then
160
164
Printf. printf
161
165
" [findArgCompletables] Completing for unlabelled argument value \
@@ -174,7 +178,8 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor
174
178
};
175
179
prefix = " " ;
176
180
nested = [] ;
177
- }))
181
+ })
182
+ | _ -> None )
178
183
else None
179
184
in
180
185
match args with
@@ -549,15 +554,17 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
549
554
let inJsxContext = ref false in
550
555
(* Identifies expressions where we can do typed pattern or expr completion. *)
551
556
let typedCompletionExpr (exp : Parsetree.expression ) =
557
+ let debugTypedCompletionExpr = false in
552
558
if exp.pexp_loc |> CursorPosition. locHasCursor ~pos: posBeforeCursor then (
553
- if Debug. verbose () then print_endline " [typedCompletionExpr] Has cursor" ;
559
+ if Debug. verbose () && debugTypedCompletionExpr then
560
+ print_endline " [typedCompletionExpr] Has cursor" ;
554
561
match exp.pexp_desc with
555
562
(* No cases means there's no `|` yet in the switch * )
556
563
| Pexp_match (({pexp_desc = Pexp_ident _ } as expr ), [] ) ->
557
- if Debug. verbose () then
564
+ if Debug. verbose () && debugTypedCompletionExpr then
558
565
print_endline " [typedCompletionExpr] No cases, with ident" ;
559
566
if locHasCursor expr.pexp_loc then (
560
- if Debug. verbose () then
567
+ if Debug. verbose () && debugTypedCompletionExpr then
561
568
print_endline " [typedCompletionExpr] No cases - has cursor" ;
562
569
(* We can do exhaustive switch completion if this is an ident we can
563
570
complete from. *)
@@ -566,7 +573,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
566
573
| Some contextPath ->
567
574
setResult (CexhaustiveSwitch {contextPath; exprLoc = exp.pexp_loc}))
568
575
| Pexp_match (_expr , [] ) ->
569
- if Debug. verbose () then
576
+ if Debug. verbose () && debugTypedCompletionExpr then
570
577
print_endline " [typedCompletionExpr] No cases, rest" ;
571
578
()
572
579
| Pexp_match
@@ -594,15 +601,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
594
601
patternMode = Default ;
595
602
}))
596
603
| Pexp_match (exp , cases ) -> (
597
- if Debug. verbose () then print_endline " [typedCompletionExpr] Has cases" ;
604
+ if Debug. verbose () && debugTypedCompletionExpr then
605
+ print_endline " [typedCompletionExpr] Has cases" ;
598
606
(* If there's more than one case, or the case isn't a pattern hole, figure out if we're completing another
599
607
broken parser case (`switch x { | true => () | <com> }` for example). *)
600
608
match exp |> exprToContextPath with
601
609
| None ->
602
- if Debug. verbose () then
610
+ if Debug. verbose () && debugTypedCompletionExpr then
603
611
print_endline " [typedCompletionExpr] Has cases - no ctx path"
604
612
| Some ctxPath -> (
605
- if Debug. verbose () then
613
+ if Debug. verbose () && debugTypedCompletionExpr then
606
614
print_endline " [typedCompletionExpr] Has cases - has ctx path" ;
607
615
let hasCaseWithCursor =
608
616
cases
@@ -616,7 +624,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
616
624
locIsEmpty case.Parsetree. pc_lhs.ppat_loc)
617
625
|> Option. is_some
618
626
in
619
- if Debug. verbose () then
627
+ if Debug. verbose () && debugTypedCompletionExpr then
620
628
Printf. printf
621
629
" [typedCompletionExpr] Has cases - has ctx path - \
622
630
hasCaseWithEmptyLoc: %b, hasCaseWithCursor: %b\n "
0 commit comments