Skip to content

Commit a050ac3

Browse files
authored
More removal of _ in expr completion (#890)
* more removal of _ in expr completion * changelog
1 parent d0c842a commit a050ac3

5 files changed

+32
-20
lines changed

CHANGELOG.md

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

15+
#### :nail_care: Polish
16+
17+
- More cases of not emitting `_` when completing in expressions. https://github.com/rescript-lang/rescript-vscode/pull/890
18+
1519
## 1.34.0
1620

1721
#### :rocket: New Feature
@@ -23,7 +27,7 @@
2327
#### :nail_care: Polish
2428

2529
- Better error recovery when analysis fails. https://github.com/rescript-lang/rescript-vscode/pull/880
26-
- Do not emit `_` when completing in patterns. https://github.com/rescript-lang/rescript-vscode/pull/885
30+
- Do not emit `_` when completing in expressions. https://github.com/rescript-lang/rescript-vscode/pull/885
2731
- 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
2832

2933
## 1.32.0

analysis/src/CompletionBackEnd.ml

+17-9
Original file line numberDiff line numberDiff line change
@@ -1168,24 +1168,32 @@ let filterItems items ~prefix =
11681168
|> List.filter (fun (item : Completion.t) ->
11691169
Utils.startsWith item.name prefix)
11701170

1171-
let printConstructorArgs argsLen ~asSnippet =
1171+
type completionMode = Pattern of Completable.patternMode | Expression
1172+
1173+
let emptyCase ~mode num =
1174+
match mode with
1175+
| Expression -> "$" ^ string_of_int (num - 1)
1176+
| Pattern _ -> "${" ^ string_of_int num ^ ":_}"
1177+
1178+
let printConstructorArgs ~mode ~asSnippet argsLen =
11721179
let args = ref [] in
11731180
for argNum = 1 to argsLen do
11741181
args :=
1175-
!args @ [(if asSnippet then Printf.sprintf "${%i:_}" argNum else "_")]
1182+
!args
1183+
@ [
1184+
(match (asSnippet, argsLen) with
1185+
| true, l when l > 1 -> Printf.sprintf "${%i:_}" argNum
1186+
| true, l when l > 0 -> emptyCase ~mode argNum
1187+
| _ -> "_");
1188+
]
11761189
done;
11771190
if List.length !args > 0 then "(" ^ (!args |> String.concat ", ") ^ ")"
11781191
else ""
11791192

1180-
type completionMode = Pattern of Completable.patternMode | Expression
1181-
11821193
let rec completeTypedValue ~rawOpens ~full ~prefix ~completionContext ~mode
11831194
(t : SharedTypes.completionType) =
1184-
let emptyCase num =
1185-
match mode with
1186-
| Expression -> "$" ^ string_of_int (num - 1)
1187-
| Pattern _ -> "${" ^ string_of_int num ^ ":_}"
1188-
in
1195+
let emptyCase = emptyCase ~mode in
1196+
let printConstructorArgs = printConstructorArgs ~mode in
11891197
match t with
11901198
| TtypeT {env; path} ->
11911199
(* Find all functions in the module that returns type t *)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ Path fnTakingPolyVariant
11631163
"tags": [],
11641164
"detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
11651165
"documentation": null,
1166-
"insertText": "#two(${1:_})",
1166+
"insertText": "#two($0)",
11671167
"insertTextFormat": 2
11681168
}]
11691169

@@ -1198,7 +1198,7 @@ Path fnTakingPolyVariant
11981198
"tags": [],
11991199
"detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]",
12001200
"documentation": null,
1201-
"insertText": "two(${1:_})",
1201+
"insertText": "two($0)",
12021202
"insertTextFormat": 2
12031203
}]
12041204

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Path CompletionSupport.TestComponent.make
6060
"detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)",
6161
"documentation": null,
6262
"sortText": "A Three(_)",
63-
"insertText": "{Three(${1:_})}",
63+
"insertText": "{Three($0)}",
6464
"insertTextFormat": 2
6565
}, {
6666
"label": "TableclothMap",
@@ -250,7 +250,7 @@ Path CompletionSupport.TestComponent.make
250250
"tags": [],
251251
"detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)",
252252
"documentation": null,
253-
"insertText": "Three(${1:_})",
253+
"insertText": "Three($0)",
254254
"insertTextFormat": 2
255255
}]
256256

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Path someVariant
5858
"tags": [],
5959
"detail": "Two(bool)\n\ntype someVariant = One | Two(bool)",
6060
"documentation": null,
61-
"insertText": "Two(${1:_})",
61+
"insertText": "Two($0)",
6262
"insertTextFormat": 2
6363
}]
6464

@@ -113,7 +113,7 @@ Path somePolyVariant
113113
"tags": [],
114114
"detail": "#two(bool)\n\n[#one | #two(bool)]",
115115
"documentation": null,
116-
"insertText": "#two(${1:_})",
116+
"insertText": "#two($0)",
117117
"insertTextFormat": 2
118118
}]
119119

@@ -240,7 +240,7 @@ Path someVariant
240240
"tags": [],
241241
"detail": "Two(bool)\n\ntype someVariant = One | Two(bool)",
242242
"documentation": null,
243-
"insertText": "Some(Two(${1:_}))",
243+
"insertText": "Some(Two($0))",
244244
"insertTextFormat": 2
245245
}]
246246

@@ -266,7 +266,7 @@ Path someVariant
266266
"tags": [],
267267
"detail": "Two(bool)\n\ntype someVariant = One | Two(bool)",
268268
"documentation": null,
269-
"insertText": "Two(${1:_})",
269+
"insertText": "Two($0)",
270270
"insertTextFormat": 2
271271
}]
272272

@@ -311,7 +311,7 @@ Path someVariant
311311
"tags": [],
312312
"detail": "Two(bool)\n\ntype someVariant = One | Two(bool)",
313313
"documentation": null,
314-
"insertText": "Two(${1:_})",
314+
"insertText": "Two($0)",
315315
"insertTextFormat": 2
316316
}]
317317

@@ -358,7 +358,7 @@ Path someVariant
358358
"tags": [],
359359
"detail": "Two(bool)\n\ntype someVariant = One | Two(bool)",
360360
"documentation": null,
361-
"insertText": "Two(${1:_})",
361+
"insertText": "Two($0)",
362362
"insertTextFormat": 2
363363
}]
364364

0 commit comments

Comments
 (0)