Skip to content

Fix special case in switch expr completion #1002

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

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## master

#### :bug: Bug Fix

- Fix edge case in switch expr completion. https://github.com/rescript-lang/rescript-vscode/pull/1002

## 1.52.0

#### :bug: Bug Fix
Expand Down
8 changes: 8 additions & 0 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
if Debug.verbose () && debugTypedCompletionExpr then
print_endline "[typedCompletionExpr] No cases, rest";
()
| Pexp_match (expr, [{pc_lhs; pc_rhs}])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment here as the case is similar to what's in the comment for the next case.

when locHasCursor expr.pexp_loc
&& CompletionExpressions.isExprHole pc_rhs
&& CompletionPatterns.isPatternHole pc_lhs ->
if Debug.verbose () && debugTypedCompletionExpr then
print_endline
"[typedCompletionExpr] No cases (expr and pat holes), rest";
()
| Pexp_match
( exp,
[
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/CompletionExpressions.res
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,6 @@ let {name} = hook({
includeName: true,
showMore: true,
})

// switch someTyp. { | }
// ^com
19 changes: 19 additions & 0 deletions analysis/tests/src/expected/CompletionExpressions.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1459,3 +1459,22 @@ Path hook
"documentation": {"kind": "markdown", "value": "```rescript\noperator?: [#\"and\" | #or]\n```\n\n```rescript\ntype config = {includeName: bool, operator: option<[#\"and\" | #or]>, showMore: bool}\n```"}
}]

Complete src/CompletionExpressions.res 388:18
posCursor:[388:18] posNoWhite:[388:17] Found expr:[388:3->388:24]
posCursor:[388:18] posNoWhite:[388:17] Found expr:[388:10->388:18]
Pexp_field [388:10->388:17] _:[388:19->388:18]
Completable: Cpath Value[someTyp].""
Raw opens: 1 CompletionSupport.place holder
Package opens Pervasives.JsxModules.place holder
Resolved opens 2 pervasives CompletionSupport.res
ContextPath Value[someTyp].""
ContextPath Value[someTyp]
Path someTyp
[{
"label": "test",
"kind": 5,
"tags": [],
"detail": "bool",
"documentation": {"kind": "markdown", "value": "```rescript\ntest: bool\n```\n\n```rescript\ntype someTyp = {test: bool}\n```"}
}]

Loading