Skip to content

Commit f22cc81

Browse files
committed
simplify setting completion pattern
1 parent 03bda7d commit f22cc81

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

analysis/src/CompletionBackEnd.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
21732173
Utils.startsWith name prefix
21742174
&& (forHover || not (List.mem name identsSeen)))
21752175
|> List.map mkLabel
2176-
| Cpattern {typ; prefix; nested = None} -> (
2176+
| Cpattern {typ; prefix; nested = []} -> (
21772177
let envWhereCompletionStarted = env in
21782178
match
21792179
typ
@@ -2186,7 +2186,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
21862186
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
21872187
~expandOption:false ~includeLocalValues:false ~completionContext:None
21882188
| None -> [])
2189-
| Cpattern {typ; prefix; nested = Some nested} -> (
2189+
| Cpattern {typ; prefix; nested} -> (
21902190
let envWhereCompletionStarted = env in
21912191
match
21922192
typ

analysis/src/CompletionFrontEnd.ml

+5-7
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
634634
in
635635
let completePattern (pat : Parsetree.pattern) =
636636
match (pat |> traversePattern ~patternPath:[], !lookingForPat) with
637-
| Some (prefix, []), Some (Completable.Cpattern p) ->
638-
setResult (Completable.Cpattern {p with prefix; nested = None})
639-
| Some (prefix, nestedPattern), Some (Cpattern p) ->
637+
| Some (prefix, nestedPattern), Some ctxPath ->
640638
setResult
641-
(Cpattern {p with prefix; nested = Some (List.rev nestedPattern)})
639+
(Completable.Cpattern
640+
{typ = ctxPath; prefix; nested = List.rev nestedPattern})
642641
| _ -> ()
643642
in
644643
let scopeValueBinding (vb : Parsetree.value_binding) =
@@ -674,8 +673,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
674673
!scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc
675674
in
676675
let setLookingForPat ctxPath =
677-
lookingForPat :=
678-
Some (Completable.Cpattern {typ = ctxPath; prefix = ""; nested = None});
676+
lookingForPat := Some ctxPath;
679677
if debug then
680678
Printf.printf "looking for: %s \n" (Completable.toString (Cpath ctxPath))
681679
in
@@ -706,7 +704,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
706704
| None -> ()
707705
| Some ctxPath ->
708706
setResult
709-
(Completable.Cpattern {typ = ctxPath; nested = None; prefix = ""}))
707+
(Completable.Cpattern {typ = ctxPath; nested = []; prefix = ""}))
710708
| Pexp_match (exp, _cases) -> (
711709
(* If there's more than one case, or the case isn't a pattern hole, set that we're looking for this path currently. *)
712710
match exp |> exprToContextPath with

analysis/src/SharedTypes.ml

+3-7
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,7 @@ module Completable = struct
592592
propName: string;
593593
prefix: string;
594594
}
595-
| Cpattern of {
596-
typ: contextPath;
597-
nested: patternPath list option;
598-
prefix: string;
599-
}
595+
| Cpattern of {typ: contextPath; nested: patternPath list; prefix: string}
600596

601597
(** An extracted type from a type expr *)
602598
type extractedType =
@@ -677,8 +673,8 @@ module Completable = struct
677673
^ (if prefix = "" then "" else "=" ^ prefix)
678674
^
679675
match nested with
680-
| None -> ""
681-
| Some patternPaths ->
676+
| [] -> ""
677+
| patternPaths ->
682678
"->"
683679
^ (patternPaths
684680
|> List.map (fun patternPath -> patternPathToString patternPath)

0 commit comments

Comments
 (0)