Skip to content

Commit e378f57

Browse files
committed
add test for patterns under other patterns, and handle unsetting what pattern we're currently looking for
1 parent a539143 commit e378f57

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

analysis/src/CompletionFrontEnd.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
416416
scope :=
417417
!scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc
418418
in
419-
420419
let lookingForPat = ref None in
421-
422420
let setLookingForPat ctxPath =
423421
lookingForPat :=
424422
Some (Completable.Cpattern {typ = ctxPath; prefix = ""; nested = None});
425423
if debug then
426424
Printf.printf "looking for: %s \n" (Completable.toString (Cpath ctxPath))
427425
in
426+
let unsetLookingForPat = lookingForPat := None in
428427
let appendNestedPat patternPat =
429428
match !lookingForPat with
430429
| Some (Completable.Cpattern ({nested = None} as p)) ->
@@ -477,7 +476,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
477476
match exp |> exprToContextPath with
478477
| None -> ()
479478
| Some ctxPath -> setLookingForPat ctxPath)
480-
| _ -> ()
479+
| _ -> unsetLookingForPat
481480
in
482481

483482
let typedCompletionPat (pat : Parsetree.pattern) =

analysis/tests/src/CompletionPattern.res

+9
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ let z = (f, true)
6363

6464
// switch f { | {nest: {}}}
6565
// ^com
66+
67+
let _ = switch f {
68+
| {first: 123, nest} =>
69+
()
70+
// switch nest { | {}}
71+
// ^com
72+
nest.nested
73+
| _ => false
74+
}

analysis/tests/src/expected/CompletionPattern.res.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Completable: Cpattern Value[z]=o->tuple($0), recordBody
169169

170170
Complete src/CompletionPattern.res 60:22
171171
looking for: Cpath Value[f]
172-
posCursor:[60:22] posNoWhite:[60:21] Found expr:[60:3->60:25]
172+
posCursor:[60:22] posNoWhite:[60:21] Found expr:[60:3->73:1]
173173
posCursor:[60:22] posNoWhite:[60:21] Found pattern:[60:16->60:25]
174174
Completable: Cpattern Value[f]->recordField(nest)
175175
[{
@@ -197,3 +197,20 @@ Completable: Cpattern Value[f]->recordField(nest), recordBody
197197
"documentation": null
198198
}]
199199

200+
Complete src/CompletionPattern.res 69:22
201+
looking for: Cpath Value[f]
202+
posCursor:[69:22] posNoWhite:[69:21] Found expr:[66:8->73:1]
203+
posCursor:[69:22] posNoWhite:[69:21] Found expr:[68:2->71:13]
204+
posCursor:[69:22] posNoWhite:[69:21] Found expr:[69:5->71:13]
205+
looking for: Cpath Value[nest]
206+
posCursor:[69:22] posNoWhite:[69:21] Found expr:[69:5->69:24]
207+
posCursor:[69:22] posNoWhite:[69:21] Found pattern:[69:21->69:23]
208+
Completable: Cpattern Value[nest]->recordBody
209+
[{
210+
"label": "nested",
211+
"kind": 5,
212+
"tags": [],
213+
"detail": "nested: bool\n\nnestedRecord",
214+
"documentation": null
215+
}]
216+

0 commit comments

Comments
 (0)