Skip to content

Commit a61f06b

Browse files
committed
handle or patterns (including broken patterns) in variant/polyvariant payloads
1 parent 9429664 commit a61f06b

File tree

3 files changed

+112
-22
lines changed

3 files changed

+112
-22
lines changed

Diff for: analysis/src/CompletionFrontEnd.ml

+18-22
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
548548
{constructorName = getUnqualifiedName txt; itemNum = 1};
549549
]
550550
@ patternPath )
551-
| Ppat_construct ({txt}, Some pat)
552-
when locHasCursor pat.ppat_loc && isPatternTuple pat = false ->
553-
(* Single payload *)
554-
pat
555-
|> traversePattern
556-
~patternPath:
557-
([
558-
Completable.PVariantPayload
559-
{constructorName = getUnqualifiedName txt; itemNum = 0};
560-
]
561-
@ patternPath)
562551
| Ppat_construct ({txt}, Some {ppat_loc; ppat_desc = Ppat_tuple tupleItems})
563552
when locHasCursor ppat_loc ->
564553
tupleItems
@@ -578,6 +567,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
578567
};
579568
]
580569
@ patternPath)
570+
| Ppat_construct ({txt}, Some p) when locHasCursor pat.ppat_loc ->
571+
p
572+
|> traversePattern
573+
~patternPath:
574+
([
575+
Completable.PVariantPayload
576+
{constructorName = getUnqualifiedName txt; itemNum = 0};
577+
]
578+
@ patternPath)
581579
| Ppat_variant
582580
( txt,
583581
Some {ppat_loc; ppat_desc = Ppat_construct ({txt = Lident "()"}, _)}
@@ -597,17 +595,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
597595
( "",
598596
[Completable.PPolyvariantPayload {constructorName = txt; itemNum = 1}]
599597
@ patternPath )
600-
| Ppat_variant (txt, Some pat)
601-
when locHasCursor pat.ppat_loc && isPatternTuple pat = false ->
602-
(* Single payload *)
603-
pat
604-
|> traversePattern
605-
~patternPath:
606-
([
607-
Completable.PPolyvariantPayload
608-
{constructorName = txt; itemNum = 0};
609-
]
610-
@ patternPath)
611598
| Ppat_variant (txt, Some {ppat_loc; ppat_desc = Ppat_tuple tupleItems})
612599
when locHasCursor ppat_loc ->
613600
tupleItems
@@ -621,6 +608,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
621608
{constructorName = txt; itemNum = itemNum + 1};
622609
]
623610
@ patternPath)
611+
| Ppat_variant (txt, Some p) when locHasCursor pat.ppat_loc ->
612+
p
613+
|> traversePattern
614+
~patternPath:
615+
([
616+
Completable.PPolyvariantPayload
617+
{constructorName = txt; itemNum = 0};
618+
]
619+
@ patternPath)
624620
| _ -> None
625621
in
626622
let completePattern (pat : Parsetree.pattern) =

Diff for: analysis/tests/src/CompletionPattern.res

+12
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,15 @@ let s = (true, Some(true), [false])
179179

180180
// switch z { | One | }
181181
// ^com
182+
183+
// switch z { | One | Two(true | ) }
184+
// ^com
185+
186+
// switch z { | One | Three({test: true}, true | ) }
187+
// ^com
188+
189+
// switch b { | #one | #two(true | ) }
190+
// ^com
191+
192+
// switch b { | #one | #three({test: true}, true | ) }
193+
// ^com

Diff for: analysis/tests/src/expected/CompletionPattern.res.txt

+82
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,85 @@ Completable: Cpattern Value[z]
752752
"insertTextFormat": 2
753753
}]
754754

755+
Complete src/CompletionPattern.res 182:32
756+
looking for: Cpath Value[z]
757+
posCursor:[182:32] posNoWhite:[182:31] Found expr:[182:3->182:37]
758+
posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:16->182:34]
759+
posCursor:[182:32] posNoWhite:[182:31] Found pattern:[182:22->182:34]
760+
Completable: Cpattern Value[z]->variantPayload::Two($0)
761+
[{
762+
"label": "true",
763+
"kind": 4,
764+
"tags": [],
765+
"detail": "bool",
766+
"documentation": null
767+
}, {
768+
"label": "false",
769+
"kind": 4,
770+
"tags": [],
771+
"detail": "bool",
772+
"documentation": null
773+
}]
774+
775+
Complete src/CompletionPattern.res 185:48
776+
looking for: Cpath Value[z]
777+
posCursor:[185:48] posNoWhite:[185:47] Found expr:[185:3->185:53]
778+
posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:16->185:50]
779+
posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:22->185:50]
780+
posCursor:[185:48] posNoWhite:[185:47] Found pattern:[185:27->185:53]
781+
Completable: Cpattern Value[z]->variantPayload::Three($1)
782+
[{
783+
"label": "true",
784+
"kind": 4,
785+
"tags": [],
786+
"detail": "bool",
787+
"documentation": null
788+
}, {
789+
"label": "false",
790+
"kind": 4,
791+
"tags": [],
792+
"detail": "bool",
793+
"documentation": null
794+
}]
795+
796+
Complete src/CompletionPattern.res 188:34
797+
looking for: Cpath Value[b]
798+
posCursor:[188:34] posNoWhite:[188:33] Found expr:[188:3->188:39]
799+
posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:16->188:36]
800+
posCursor:[188:34] posNoWhite:[188:33] Found pattern:[188:23->188:36]
801+
Completable: Cpattern Value[b]->polyvariantPayload::two($0)
802+
[{
803+
"label": "true",
804+
"kind": 4,
805+
"tags": [],
806+
"detail": "bool",
807+
"documentation": null
808+
}, {
809+
"label": "false",
810+
"kind": 4,
811+
"tags": [],
812+
"detail": "bool",
813+
"documentation": null
814+
}]
815+
816+
Complete src/CompletionPattern.res 191:50
817+
looking for: Cpath Value[b]
818+
posCursor:[191:50] posNoWhite:[191:49] Found expr:[191:3->191:55]
819+
posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:16->191:52]
820+
posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:23->191:52]
821+
posCursor:[191:50] posNoWhite:[191:49] Found pattern:[191:29->191:52]
822+
Completable: Cpattern Value[b]->polyvariantPayload::three($1)
823+
[{
824+
"label": "true",
825+
"kind": 4,
826+
"tags": [],
827+
"detail": "bool",
828+
"documentation": null
829+
}, {
830+
"label": "false",
831+
"kind": 4,
832+
"tags": [],
833+
"detail": "bool",
834+
"documentation": null
835+
}]
836+

0 commit comments

Comments
 (0)