Skip to content

Commit 95f77e1

Browse files
authored
handle completion for polyvars without leading # (#874)
* handle completion for polyvars without leading # * changelog
1 parent a5d252c commit 95f77e1

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix so that you don't need a leading `#` to complete for polyvariant constructors. https://github.com/rescript-lang/rescript-vscode/pull/874
18+
1519
## 1.30.0
1620

1721
#### :rocket: New Feature

analysis/src/CompletionBackEnd.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,8 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
12371237
(PolyvariantConstructor
12381238
(constructor, typeExpr |> Shared.typeToString))
12391239
~env ())
1240-
|> filterItems ~prefix
1240+
|> filterItems
1241+
~prefix:(if Utils.startsWith prefix "#" then prefix else "#" ^ prefix)
12411242
| Toption (env, t) ->
12421243
let innerType =
12431244
match t with

analysis/tests/src/CompletionExpressions.res

+16
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,19 @@ let takesExotic = (e: exoticPolyvariant) => {
271271

272272
// takesExotic()
273273
// ^com
274+
275+
let fnTakingPolyVariant = (a: somePolyVariant) => {
276+
ignore(a)
277+
}
278+
279+
// fnTakingPolyVariant()
280+
// ^com
281+
282+
// fnTakingPolyVariant(#)
283+
// ^com
284+
285+
// fnTakingPolyVariant(#o)
286+
// ^com
287+
288+
// fnTakingPolyVariant(o)
289+
// ^com

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

+108
Original file line numberDiff line numberDiff line change
@@ -1132,3 +1132,111 @@ Path takesExotic
11321132
"insertTextFormat": 2
11331133
}]
11341134

1135+
Complete src/CompletionExpressions.res 278:23
1136+
posCursor:[278:23] posNoWhite:[278:22] Found expr:[278:3->278:24]
1137+
Pexp_apply ...[278:3->278:22] (...[278:23->278:24])
1138+
Completable: Cexpression CArgument Value[fnTakingPolyVariant]($0)
1139+
Package opens Pervasives.JsxModules.place holder
1140+
Resolved opens 1 pervasives
1141+
ContextPath CArgument Value[fnTakingPolyVariant]($0)
1142+
ContextPath Value[fnTakingPolyVariant]
1143+
Path fnTakingPolyVariant
1144+
[{
1145+
"label": "#one",
1146+
"kind": 4,
1147+
"tags": [],
1148+
"detail": "#one\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1149+
"documentation": null,
1150+
"insertText": "#one",
1151+
"insertTextFormat": 2
1152+
}, {
1153+
"label": "#three(_, _)",
1154+
"kind": 4,
1155+
"tags": [],
1156+
"detail": "#three(someRecord, bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1157+
"documentation": null,
1158+
"insertText": "#three(${1:_}, ${2:_})",
1159+
"insertTextFormat": 2
1160+
}, {
1161+
"label": "#two(_)",
1162+
"kind": 4,
1163+
"tags": [],
1164+
"detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1165+
"documentation": null,
1166+
"insertText": "#two(${1:_})",
1167+
"insertTextFormat": 2
1168+
}]
1169+
1170+
Complete src/CompletionExpressions.res 281:24
1171+
posCursor:[281:24] posNoWhite:[281:23] Found expr:[281:3->281:25]
1172+
Pexp_apply ...[281:3->281:22] (...[281:23->281:25])
1173+
Completable: Cexpression CArgument Value[fnTakingPolyVariant]($0)=#
1174+
Package opens Pervasives.JsxModules.place holder
1175+
Resolved opens 1 pervasives
1176+
ContextPath CArgument Value[fnTakingPolyVariant]($0)
1177+
ContextPath Value[fnTakingPolyVariant]
1178+
Path fnTakingPolyVariant
1179+
[{
1180+
"label": "#one",
1181+
"kind": 4,
1182+
"tags": [],
1183+
"detail": "#one\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1184+
"documentation": null,
1185+
"insertText": "one",
1186+
"insertTextFormat": 2
1187+
}, {
1188+
"label": "#three(_, _)",
1189+
"kind": 4,
1190+
"tags": [],
1191+
"detail": "#three(someRecord, bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1192+
"documentation": null,
1193+
"insertText": "three(${1:_}, ${2:_})",
1194+
"insertTextFormat": 2
1195+
}, {
1196+
"label": "#two(_)",
1197+
"kind": 4,
1198+
"tags": [],
1199+
"detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1200+
"documentation": null,
1201+
"insertText": "two(${1:_})",
1202+
"insertTextFormat": 2
1203+
}]
1204+
1205+
Complete src/CompletionExpressions.res 284:25
1206+
posCursor:[284:25] posNoWhite:[284:24] Found expr:[284:3->284:26]
1207+
Pexp_apply ...[284:3->284:22] (...[284:23->284:25])
1208+
Completable: Cexpression CArgument Value[fnTakingPolyVariant]($0)=#o
1209+
Package opens Pervasives.JsxModules.place holder
1210+
Resolved opens 1 pervasives
1211+
ContextPath CArgument Value[fnTakingPolyVariant]($0)
1212+
ContextPath Value[fnTakingPolyVariant]
1213+
Path fnTakingPolyVariant
1214+
[{
1215+
"label": "#one",
1216+
"kind": 4,
1217+
"tags": [],
1218+
"detail": "#one\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1219+
"documentation": null,
1220+
"insertText": "one",
1221+
"insertTextFormat": 2
1222+
}]
1223+
1224+
Complete src/CompletionExpressions.res 287:24
1225+
posCursor:[287:24] posNoWhite:[287:23] Found expr:[287:3->287:25]
1226+
Pexp_apply ...[287:3->287:22] (...[287:23->287:24])
1227+
Completable: Cexpression CArgument Value[fnTakingPolyVariant]($0)=o
1228+
Package opens Pervasives.JsxModules.place holder
1229+
Resolved opens 1 pervasives
1230+
ContextPath CArgument Value[fnTakingPolyVariant]($0)
1231+
ContextPath Value[fnTakingPolyVariant]
1232+
Path fnTakingPolyVariant
1233+
[{
1234+
"label": "#one",
1235+
"kind": 4,
1236+
"tags": [],
1237+
"detail": "#one\n\n[#one | #three(someRecord, bool) | #two(bool)]",
1238+
"documentation": null,
1239+
"insertText": "#one",
1240+
"insertTextFormat": 2
1241+
}]
1242+

0 commit comments

Comments
 (0)