Skip to content

Commit 29a3df2

Browse files
zthcristianoc
authored andcommitted
factor away lookingForPat
1 parent ec6ec7a commit 29a3df2

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
392392
| Ppat_extension _ -> ()
393393
| Ppat_open (_, p) -> scopePattern ~patternPath ?contextPath p
394394
in
395-
396-
let lookingForPat = ref None in
397-
398395
let locHasCursor = CursorPosition.locHasCursor ~pos:posBeforeCursor in
399396
let locIsEmpty = CursorPosition.locIsEmpty ~pos:posBeforeCursor in
400-
401-
let completePattern (pat : Parsetree.pattern) =
397+
let completePattern ?contextPath (pat : Parsetree.pattern) =
402398
match
403399
( pat
404400
|> CompletionPatterns.traversePattern ~patternPath:[] ~locHasCursor
405401
~firstCharBeforeCursorNoWhite ~posBeforeCursor,
406-
!lookingForPat )
402+
contextPath )
407403
with
408404
| Some (prefix, nestedPattern), Some ctxPath ->
409405
setResult
@@ -456,11 +452,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
456452
scope :=
457453
!scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc
458454
in
459-
(* TODO: Can get rid of setLookingForPat soon *)
460-
let setLookingForPat ctxPath = lookingForPat := Some ctxPath in
461455
let inJsxContext = ref false in
462-
463-
let unsetLookingForPat () = lookingForPat := None in
464456
(* Identifies expressions where we can do typed pattern or expr completion. *)
465457
let typedCompletionExpr (exp : Parsetree.expression) =
466458
if exp.pexp_loc |> CursorPosition.locHasCursor ~pos:posBeforeCursor then
@@ -520,7 +512,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
520512
match (hasCaseWithEmptyLoc, hasCaseWithCursor) with
521513
| _, true ->
522514
(* Always continue if there's a case with the cursor *)
523-
setLookingForPat ctxPath
515+
()
524516
| true, false ->
525517
(* If there's no case with the cursor, but a broken parser case, complete for the top level. *)
526518
setResult
@@ -533,7 +525,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
533525
patternMode = Default;
534526
})
535527
| false, false -> ()))
536-
| _ -> unsetLookingForPat ()
528+
| _ -> ()
537529
in
538530
let structure (iterator : Ast_iterator.iterator)
539531
(structure : Parsetree.structure) =
@@ -543,7 +535,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
543535
in
544536
let structure_item (iterator : Ast_iterator.iterator)
545537
(item : Parsetree.structure_item) =
546-
unsetLookingForPat ();
547538
let processed = ref false in
548539
(match item.pstr_desc with
549540
| Pstr_open {popen_lid} ->
@@ -788,7 +779,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
788779
|> List.iter (fun (case : Parsetree.case) ->
789780
let oldScope = !scope in
790781
scopePattern ?contextPath:ctxPath case.pc_lhs;
791-
completePattern case.pc_lhs;
782+
completePattern ?contextPath:ctxPath case.pc_lhs;
792783
Ast_iterator.default_iterator.case iterator case;
793784
scope := oldScope);
794785
resetCurrentCtxPath oldCtxPath
@@ -1033,12 +1024,9 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
10331024
(match defaultExpOpt with
10341025
| None -> ()
10351026
| 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;
10421030
iterator.pat iterator pat;
10431031
iterator.expr iterator e;
10441032
scope := oldScope;

0 commit comments

Comments
 (0)