Skip to content

Commit c3ea53b

Browse files
committed
handle options
1 parent 0f9be34 commit c3ea53b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

analysis/src/CompletionBackEnd.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1780,8 +1780,11 @@ let rec resolveNestedPattern typ ~env ~package ~nested =
17801780
| Some {typ} -> typ |> resolveNestedPattern ~env ~package ~nested)
17811781
| PRecordBody {seenFields}, Some (Trecord {env; typeExpr}) ->
17821782
Some (typeExpr, env, Some (Completable.RecordField {seenFields}))
1783-
| PVariantPayload {constructorName; itemNum}, Some (Tvariant {env; constructors})
1784-
-> (
1783+
| ( PVariantPayload {constructorName = "Some"; itemNum = 0},
1784+
Some (Toption (env, typ)) ) ->
1785+
typ |> resolveNestedPattern ~env ~package ~nested
1786+
| ( PVariantPayload {constructorName; itemNum},
1787+
Some (Tvariant {env; constructors}) ) -> (
17851788
match
17861789
constructors
17871790
|> List.find_opt (fun (c : Constructor.t) ->

analysis/tests/src/CompletionPattern.res

+6
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ ignore(c)
121121

122122
// switch c { | [] }
123123
// ^com
124+
125+
let o = Some(true)
126+
ignore(o)
127+
128+
// switch o { | Some() }
129+
// ^com

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

+20
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,23 @@ Completable: Cpattern Value[c]->array
453453
"documentation": null
454454
}]
455455

456+
Complete src/CompletionPattern.res 127:21
457+
looking for: Cpath Value[o]
458+
posCursor:[127:21] posNoWhite:[127:20] Found expr:[127:3->127:24]
459+
posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:16->127:22]
460+
posCursor:[127:21] posNoWhite:[127:20] Found pattern:[127:20->127:22]
461+
Completable: Cpattern Value[o]->variantPayload::Some($0)
462+
[{
463+
"label": "true",
464+
"kind": 4,
465+
"tags": [],
466+
"detail": "bool",
467+
"documentation": null
468+
}, {
469+
"label": "false",
470+
"kind": 4,
471+
"tags": [],
472+
"detail": "bool",
473+
"documentation": null
474+
}]
475+

0 commit comments

Comments
 (0)