Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not emit _ when completing expressions #885

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Expand type aliases in hovers. https://github.com/rescript-lang/rescript-vscode/pull/881
- 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
- Complete domProps for lowercase JSX components from `ReactDOM.domProps` if possible. https://github.com/rescript-lang/rescript-vscode/pull/883
- Do not emit `_` when completing in patterns. https://github.com/rescript-lang/rescript-vscode/pull/885

## 1.32.0

Expand Down
15 changes: 12 additions & 3 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ type completionMode = Pattern of Completable.patternMode | Expression

let rec completeTypedValue ~full ~prefix ~completionContext ~mode
(t : SharedTypes.completionType) =
let emptyCase num =
match mode with
| Expression -> "$" ^ string_of_int (num - 1)
| Pattern _ -> "${" ^ string_of_int num ^ ":_}"
in
match t with
| Tbool env ->
[
Expand Down Expand Up @@ -1278,7 +1283,9 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
let noneCase = Completion.create "None" ~kind:(kindFromInnerType t) ~env in
let someAnyCase =
Completion.createWithSnippet ~name:"Some(_)" ~kind:(kindFromInnerType t)
~env ~insertText:"Some(${1:_})" ()
~env
~insertText:(Printf.sprintf "Some(%s)" (emptyCase 1))
()
in
let completions =
match completionContext with
Expand Down Expand Up @@ -1338,11 +1345,13 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
in
let okAnyCase =
Completion.createWithSnippet ~name:"Ok(_)" ~kind:(Value okType) ~env
~insertText:"Ok(${1:_})" ()
~insertText:(Printf.sprintf "Ok(%s)" (emptyCase 1))
()
in
let errorAnyCase =
Completion.createWithSnippet ~name:"Error(_)" ~kind:(Value errorType) ~env
~insertText:"Error(${1:_})" ()
~insertText:(Printf.sprintf "Error(%s)" (emptyCase 1))
()
in
let completions =
match completionContext with
Expand Down
10 changes: 5 additions & 5 deletions analysis/tests/src/expected/CompletionExpressions.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Path fnTakingRecord
"tags": [],
"detail": "otherRecord",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "None",
Expand Down Expand Up @@ -411,7 +411,7 @@ Path fnTakingArray
"tags": [],
"detail": "bool",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Some(true)",
Expand Down Expand Up @@ -488,7 +488,7 @@ Path fnTakingArray
"tags": [],
"detail": "bool",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Some(true)",
Expand Down Expand Up @@ -525,7 +525,7 @@ Path fnTakingArray
"tags": [],
"detail": "bool",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Some(true)",
Expand Down Expand Up @@ -624,7 +624,7 @@ Path fnTakingRecordWithOptVariant
"tags": [],
"detail": "someVariant",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "None",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Path someFnTakingVariant
"detail": "someVariant",
"documentation": null,
"sortText": "A Some(_)",
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Sort",
Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/CompletionTypeAnnotation.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Path someTuple
"tags": [],
"detail": "bool",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Some(true)",
Expand Down Expand Up @@ -224,7 +224,7 @@ Path someVariant
"tags": [],
"detail": "type someVariant = One | Two(bool)",
"documentation": null,
"insertText": "Some(${1:_})",
"insertText": "Some($0)",
"insertTextFormat": 2
}, {
"label": "Some(One)",
Expand Down
Loading