@@ -549,18 +549,26 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
549
549
let inJsxContext = ref false in
550
550
(* Identifies expressions where we can do typed pattern or expr completion. *)
551
551
let typedCompletionExpr (exp : Parsetree.expression ) =
552
- if exp.pexp_loc |> CursorPosition. locHasCursor ~pos: posBeforeCursor then
552
+ if exp.pexp_loc |> CursorPosition. locHasCursor ~pos: posBeforeCursor then (
553
+ if Debug. verbose () then print_endline " [typedCompletionExpr] Has cursor" ;
553
554
match exp.pexp_desc with
554
555
(* No cases means there's no `|` yet in the switch * )
555
- | Pexp_match (({pexp_desc = Pexp_ident _ } as expr ), [] ) -> (
556
- if locHasCursor expr.pexp_loc then
556
+ | Pexp_match (({pexp_desc = Pexp_ident _ } as expr ), [] ) ->
557
+ if Debug. verbose () then
558
+ print_endline " [typedCompletionExpr] No cases, with ident" ;
559
+ if locHasCursor expr.pexp_loc then (
560
+ if Debug. verbose () then
561
+ print_endline " [typedCompletionExpr] No cases - has cursor" ;
557
562
(* We can do exhaustive switch completion if this is an ident we can
558
563
complete from. *)
559
564
match exprToContextPath expr with
560
565
| None -> ()
561
566
| Some contextPath ->
562
567
setResult (CexhaustiveSwitch {contextPath; exprLoc = exp.pexp_loc}))
563
- | Pexp_match (_expr , [] ) -> ()
568
+ | Pexp_match (_expr , [] ) ->
569
+ if Debug. verbose () then
570
+ print_endline " [typedCompletionExpr] No cases, rest" ;
571
+ ()
564
572
| Pexp_match
565
573
( exp,
566
574
[
@@ -586,11 +594,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
586
594
patternMode = Default ;
587
595
}))
588
596
| Pexp_match (exp , cases ) -> (
597
+ if Debug. verbose () then print_endline " [typedCompletionExpr] Has cases" ;
589
598
(* If there's more than one case, or the case isn't a pattern hole, figure out if we're completing another
590
599
broken parser case (`switch x { | true => () | <com> }` for example). *)
591
600
match exp |> exprToContextPath with
592
- | None -> ()
601
+ | None ->
602
+ if Debug. verbose () then
603
+ print_endline " [typedCompletionExpr] Has cases - no ctx path"
593
604
| Some ctxPath -> (
605
+ if Debug. verbose () then
606
+ print_endline " [typedCompletionExpr] Has cases - has ctx path" ;
594
607
let hasCaseWithCursor =
595
608
cases
596
609
|> List. find_opt (fun case ->
@@ -603,6 +616,11 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
603
616
locIsEmpty case.Parsetree. pc_lhs.ppat_loc)
604
617
|> Option. is_some
605
618
in
619
+ if Debug. verbose () then
620
+ Printf. printf
621
+ " [typedCompletionExpr] Has cases - has ctx path - \
622
+ hasCaseWithEmptyLoc: %b, hasCaseWithCursor: %b\n "
623
+ hasCaseWithEmptyLoc hasCaseWithCursor;
606
624
match (hasCaseWithEmptyLoc, hasCaseWithCursor) with
607
625
| _ , true ->
608
626
(* Always continue if there's a case with the cursor *)
@@ -619,7 +637,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
619
637
patternMode = Default ;
620
638
})
621
639
| false , false -> () ))
622
- | _ -> ()
640
+ | _ -> () )
623
641
in
624
642
let structure (iterator : Ast_iterator.iterator )
625
643
(structure : Parsetree.structure ) =
@@ -977,7 +995,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
977
995
in
978
996
typedCompletionExpr expr;
979
997
match expr.pexp_desc with
980
- | Pexp_match (expr , cases ) when cases <> [] ->
998
+ | Pexp_match (expr, cases)
999
+ when cases <> [] && locHasCursor expr.pexp_loc = false ->
1000
+ if Debug. verbose () then
1001
+ print_endline " [completionFrontend] Checking each case" ;
981
1002
let ctxPath = exprToContextPath expr in
982
1003
let oldCtxPath = ! currentCtxPath in
983
1004
cases
0 commit comments