Skip to content

Commit a8f2b54

Browse files
authored
Do not emit _ when completing expressions (#885)
* do not emit _ when completing expressions * changelog
1 parent 4c71dab commit a8f2b54

5 files changed

+21
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Expand type aliases in hovers. https://github.com/rescript-lang/rescript-vscode/pull/881
1717
- Include fields when completing a braced expr that's an ID, where it the path likely starts with a module. https://github.com/rescript-lang/rescript-vscode/pull/882
1818
- Complete domProps for lowercase JSX components from `ReactDOM.domProps` if possible. https://github.com/rescript-lang/rescript-vscode/pull/883
19+
- Do not emit `_` when completing in patterns. https://github.com/rescript-lang/rescript-vscode/pull/885
1920

2021
## 1.32.0
2122

analysis/src/CompletionBackEnd.ml

+12-3
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,11 @@ type completionMode = Pattern of Completable.patternMode | Expression
12041204

12051205
let rec completeTypedValue ~full ~prefix ~completionContext ~mode
12061206
(t : SharedTypes.completionType) =
1207+
let emptyCase num =
1208+
match mode with
1209+
| Expression -> "$" ^ string_of_int (num - 1)
1210+
| Pattern _ -> "${" ^ string_of_int num ^ ":_}"
1211+
in
12071212
match t with
12081213
| Tbool env ->
12091214
[
@@ -1278,7 +1283,9 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
12781283
let noneCase = Completion.create "None" ~kind:(kindFromInnerType t) ~env in
12791284
let someAnyCase =
12801285
Completion.createWithSnippet ~name:"Some(_)" ~kind:(kindFromInnerType t)
1281-
~env ~insertText:"Some(${1:_})" ()
1286+
~env
1287+
~insertText:(Printf.sprintf "Some(%s)" (emptyCase 1))
1288+
()
12821289
in
12831290
let completions =
12841291
match completionContext with
@@ -1338,11 +1345,13 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
13381345
in
13391346
let okAnyCase =
13401347
Completion.createWithSnippet ~name:"Ok(_)" ~kind:(Value okType) ~env
1341-
~insertText:"Ok(${1:_})" ()
1348+
~insertText:(Printf.sprintf "Ok(%s)" (emptyCase 1))
1349+
()
13421350
in
13431351
let errorAnyCase =
13441352
Completion.createWithSnippet ~name:"Error(_)" ~kind:(Value errorType) ~env
1345-
~insertText:"Error(${1:_})" ()
1353+
~insertText:(Printf.sprintf "Error(%s)" (emptyCase 1))
1354+
()
13461355
in
13471356
let completions =
13481357
match completionContext with

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Path fnTakingRecord
204204
"tags": [],
205205
"detail": "otherRecord",
206206
"documentation": null,
207-
"insertText": "Some(${1:_})",
207+
"insertText": "Some($0)",
208208
"insertTextFormat": 2
209209
}, {
210210
"label": "None",
@@ -411,7 +411,7 @@ Path fnTakingArray
411411
"tags": [],
412412
"detail": "bool",
413413
"documentation": null,
414-
"insertText": "Some(${1:_})",
414+
"insertText": "Some($0)",
415415
"insertTextFormat": 2
416416
}, {
417417
"label": "Some(true)",
@@ -488,7 +488,7 @@ Path fnTakingArray
488488
"tags": [],
489489
"detail": "bool",
490490
"documentation": null,
491-
"insertText": "Some(${1:_})",
491+
"insertText": "Some($0)",
492492
"insertTextFormat": 2
493493
}, {
494494
"label": "Some(true)",
@@ -525,7 +525,7 @@ Path fnTakingArray
525525
"tags": [],
526526
"detail": "bool",
527527
"documentation": null,
528-
"insertText": "Some(${1:_})",
528+
"insertText": "Some($0)",
529529
"insertTextFormat": 2
530530
}, {
531531
"label": "Some(true)",
@@ -624,7 +624,7 @@ Path fnTakingRecordWithOptVariant
624624
"tags": [],
625625
"detail": "someVariant",
626626
"documentation": null,
627-
"insertText": "Some(${1:_})",
627+
"insertText": "Some($0)",
628628
"insertTextFormat": 2
629629
}, {
630630
"label": "None",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Path someFnTakingVariant
201201
"detail": "someVariant",
202202
"documentation": null,
203203
"sortText": "A Some(_)",
204-
"insertText": "Some(${1:_})",
204+
"insertText": "Some($0)",
205205
"insertTextFormat": 2
206206
}, {
207207
"label": "Sort",

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Path someTuple
188188
"tags": [],
189189
"detail": "bool",
190190
"documentation": null,
191-
"insertText": "Some(${1:_})",
191+
"insertText": "Some($0)",
192192
"insertTextFormat": 2
193193
}, {
194194
"label": "Some(true)",
@@ -224,7 +224,7 @@ Path someVariant
224224
"tags": [],
225225
"detail": "type someVariant = One | Two(bool)",
226226
"documentation": null,
227-
"insertText": "Some(${1:_})",
227+
"insertText": "Some($0)",
228228
"insertTextFormat": 2
229229
}, {
230230
"label": "Some(One)",

0 commit comments

Comments
 (0)