@@ -549,18 +549,26 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
549549 let inJsxContext = ref false in
550550 (* Identifies expressions where we can do typed pattern or expr completion. *)
551551 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" ;
553554 match exp.pexp_desc with
554555 (* 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" ;
557562 (* We can do exhaustive switch completion if this is an ident we can
558563 complete from. *)
559564 match exprToContextPath expr with
560565 | None -> ()
561566 | Some contextPath ->
562567 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+ ()
564572 | Pexp_match
565573 ( exp,
566574 [
@@ -586,11 +594,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
586594 patternMode = Default ;
587595 }))
588596 | Pexp_match (exp , cases ) -> (
597+ if Debug. verbose () then print_endline " [typedCompletionExpr] Has cases" ;
589598 (* If there's more than one case, or the case isn't a pattern hole, figure out if we're completing another
590599 broken parser case (`switch x { | true => () | <com> }` for example). *)
591600 match exp |> exprToContextPath with
592- | None -> ()
601+ | None ->
602+ if Debug. verbose () then
603+ print_endline " [typedCompletionExpr] Has cases - no ctx path"
593604 | Some ctxPath -> (
605+ if Debug. verbose () then
606+ print_endline " [typedCompletionExpr] Has cases - has ctx path" ;
594607 let hasCaseWithCursor =
595608 cases
596609 |> List. find_opt (fun case ->
@@ -603,6 +616,11 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
603616 locIsEmpty case.Parsetree. pc_lhs.ppat_loc)
604617 |> Option. is_some
605618 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;
606624 match (hasCaseWithEmptyLoc, hasCaseWithCursor) with
607625 | _ , true ->
608626 (* Always continue if there's a case with the cursor *)
@@ -619,7 +637,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
619637 patternMode = Default ;
620638 })
621639 | false , false -> () ))
622- | _ -> ()
640+ | _ -> () )
623641 in
624642 let structure (iterator : Ast_iterator.iterator )
625643 (structure : Parsetree.structure ) =
@@ -977,7 +995,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
977995 in
978996 typedCompletionExpr expr;
979997 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" ;
9811002 let ctxPath = exprToContextPath expr in
9821003 let oldCtxPath = ! currentCtxPath in
9831004 cases
0 commit comments