@@ -392,18 +392,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
392
392
| Ppat_extension _ -> ()
393
393
| Ppat_open (_ , p ) -> scopePattern ~pattern Path ?contextPath p
394
394
in
395
-
396
- let lookingForPat = ref None in
397
-
398
395
let locHasCursor = CursorPosition. locHasCursor ~pos: posBeforeCursor in
399
396
let locIsEmpty = CursorPosition. locIsEmpty ~pos: posBeforeCursor in
400
-
401
- let completePattern (pat : Parsetree.pattern ) =
397
+ let completePattern ?contextPath (pat : Parsetree.pattern ) =
402
398
match
403
399
( pat
404
400
|> CompletionPatterns. traversePattern ~pattern Path:[] ~loc HasCursor
405
401
~first CharBeforeCursorNoWhite ~pos BeforeCursor,
406
- ! lookingForPat )
402
+ contextPath )
407
403
with
408
404
| Some (prefix , nestedPattern ), Some ctxPath ->
409
405
setResult
@@ -456,11 +452,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
456
452
scope :=
457
453
! scope |> Scope. addModule ~name: md.pmd_name.txt ~loc: md.pmd_name.loc
458
454
in
459
- (* TODO: Can get rid of setLookingForPat soon *)
460
- let setLookingForPat ctxPath = lookingForPat := Some ctxPath in
461
455
let inJsxContext = ref false in
462
-
463
- let unsetLookingForPat () = lookingForPat := None in
464
456
(* Identifies expressions where we can do typed pattern or expr completion. *)
465
457
let typedCompletionExpr (exp : Parsetree.expression ) =
466
458
if exp.pexp_loc |> CursorPosition. locHasCursor ~pos: posBeforeCursor then
@@ -520,7 +512,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
520
512
match (hasCaseWithEmptyLoc, hasCaseWithCursor) with
521
513
| _ , true ->
522
514
(* Always continue if there's a case with the cursor *)
523
- setLookingForPat ctxPath
515
+ ()
524
516
| true , false ->
525
517
(* If there's no case with the cursor, but a broken parser case, complete for the top level. *)
526
518
setResult
@@ -533,7 +525,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
533
525
patternMode = Default ;
534
526
})
535
527
| false , false -> () ))
536
- | _ -> unsetLookingForPat ()
528
+ | _ -> ()
537
529
in
538
530
let structure (iterator : Ast_iterator.iterator )
539
531
(structure : Parsetree.structure ) =
@@ -543,7 +535,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
543
535
in
544
536
let structure_item (iterator : Ast_iterator.iterator )
545
537
(item : Parsetree.structure_item ) =
546
- unsetLookingForPat () ;
547
538
let processed = ref false in
548
539
(match item.pstr_desc with
549
540
| Pstr_open {popen_lid} ->
@@ -788,7 +779,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
788
779
|> List. iter (fun (case : Parsetree.case ) ->
789
780
let oldScope = ! scope in
790
781
scopePattern ?contextPath:ctxPath case.pc_lhs;
791
- completePattern case.pc_lhs;
782
+ completePattern ?contextPath:ctxPath case.pc_lhs;
792
783
Ast_iterator. default_iterator.case iterator case;
793
784
scope := oldScope);
794
785
resetCurrentCtxPath oldCtxPath
@@ -1033,12 +1024,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
1033
1024
(match defaultExpOpt with
1034
1025
| None -> ()
1035
1026
| Some defaultExp -> iterator.expr iterator defaultExp);
1036
- (match ! currentCtxPath with
1037
- | None -> ()
1038
- | Some ctxPath -> setLookingForPat ctxPath);
1039
- completePattern pat;
1040
- unsetLookingForPat () ;
1041
- scopePattern ?contextPath:! currentCtxPath pat;
1027
+ let currentContextPath = ! currentCtxPath in
1028
+ completePattern ?contextPath:currentContextPath pat;
1029
+ scopePattern ?contextPath:currentContextPath pat;
1042
1030
iterator.pat iterator pat;
1043
1031
iterator.expr iterator e;
1044
1032
scope := oldScope;
0 commit comments