Skip to content

Commit 7309bef

Browse files
committed
do not emit _ when completing expressions
1 parent 2d1742a commit 7309bef

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Diff for: analysis/src/CompletionBackEnd.ml

+13-4
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ let mkItem ~name ~kind ~detail ~deprecated ~docstring =
567567
detail;
568568
documentation =
569569
(if docContent = "" then None
570-
else Some {kind = "markdown"; value = docContent});
570+
else Some {kind = "markdown"; value = docContent});
571571
sortText = None;
572572
insertText = None;
573573
insertTextFormat = None;
@@ -1191,6 +1191,11 @@ type completionMode = Pattern of Completable.patternMode | Expression
11911191

11921192
let rec completeTypedValue ~full ~prefix ~completionContext ~mode
11931193
(t : SharedTypes.completionType) =
1194+
let emptyCase num =
1195+
match mode with
1196+
| Expression -> "$" ^ string_of_int (num - 1)
1197+
| Pattern _ -> "${" ^ string_of_int num ^ ":_}"
1198+
in
11941199
match t with
11951200
| Tbool env ->
11961201
[
@@ -1265,7 +1270,9 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
12651270
let noneCase = Completion.create "None" ~kind:(kindFromInnerType t) ~env in
12661271
let someAnyCase =
12671272
Completion.createWithSnippet ~name:"Some(_)" ~kind:(kindFromInnerType t)
1268-
~env ~insertText:"Some(${1:_})" ()
1273+
~env
1274+
~insertText:(Printf.sprintf "Some(%s)" (emptyCase 1))
1275+
()
12691276
in
12701277
let completions =
12711278
match completionContext with
@@ -1325,11 +1332,13 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
13251332
in
13261333
let okAnyCase =
13271334
Completion.createWithSnippet ~name:"Ok(_)" ~kind:(Value okType) ~env
1328-
~insertText:"Ok(${1:_})" ()
1335+
~insertText:(Printf.sprintf "Ok(%s)" (emptyCase 1))
1336+
()
13291337
in
13301338
let errorAnyCase =
13311339
Completion.createWithSnippet ~name:"Error(_)" ~kind:(Value errorType) ~env
1332-
~insertText:"Error(${1:_})" ()
1340+
~insertText:(Printf.sprintf "Error(%s)" (emptyCase 1))
1341+
()
13331342
in
13341343
let completions =
13351344
match completionContext with

Diff for: 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",

Diff for: 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",

Diff for: 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)