Skip to content

Commit 5734b9f

Browse files
authored
Fix special case in switch expr completion (#1002)
* fixes a special case in switch expr completion * changelog * add comments
1 parent 169da71 commit 5734b9f

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

CHANGELOG.md

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

15+
#### :bug: Bug Fix
16+
17+
- Fix edge case in switch expr completion. https://github.com/rescript-lang/rescript-vscode/pull/1002
18+
1519
## 1.52.0
1620

1721
#### :bug: Bug Fix

analysis/src/CompletionFrontEnd.ml

+10
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,19 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
584584
| Some contextPath ->
585585
setResult (CexhaustiveSwitch {contextPath; exprLoc = exp.pexp_loc}))
586586
| Pexp_match (_expr, []) ->
587+
(* switch x { } *)
587588
if Debug.verbose () && debugTypedCompletionExpr then
588589
print_endline "[typedCompletionExpr] No cases, rest";
589590
()
591+
| Pexp_match (expr, [{pc_lhs; pc_rhs}])
592+
when locHasCursor expr.pexp_loc
593+
&& CompletionExpressions.isExprHole pc_rhs
594+
&& CompletionPatterns.isPatternHole pc_lhs ->
595+
(* switch x { | } when we're in the switch expr itself. *)
596+
if Debug.verbose () && debugTypedCompletionExpr then
597+
print_endline
598+
"[typedCompletionExpr] No cases (expr and pat holes), rest";
599+
()
590600
| Pexp_match
591601
( exp,
592602
[

analysis/tests/src/CompletionExpressions.res

+3
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,6 @@ let {name} = hook({
385385
includeName: true,
386386
showMore: true,
387387
})
388+
389+
// switch someTyp. { | }
390+
// ^com

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

+19
Original file line numberDiff line numberDiff line change
@@ -1459,3 +1459,22 @@ Path hook
14591459
"documentation": {"kind": "markdown", "value": "```rescript\noperator?: [#\"and\" | #or]\n```\n\n```rescript\ntype config = {includeName: bool, operator: option<[#\"and\" | #or]>, showMore: bool}\n```"}
14601460
}]
14611461

1462+
Complete src/CompletionExpressions.res 388:18
1463+
posCursor:[388:18] posNoWhite:[388:17] Found expr:[388:3->388:24]
1464+
posCursor:[388:18] posNoWhite:[388:17] Found expr:[388:10->388:18]
1465+
Pexp_field [388:10->388:17] _:[388:19->388:18]
1466+
Completable: Cpath Value[someTyp].""
1467+
Raw opens: 1 CompletionSupport.place holder
1468+
Package opens Pervasives.JsxModules.place holder
1469+
Resolved opens 2 pervasives CompletionSupport.res
1470+
ContextPath Value[someTyp].""
1471+
ContextPath Value[someTyp]
1472+
Path someTyp
1473+
[{
1474+
"label": "test",
1475+
"kind": 5,
1476+
"tags": [],
1477+
"detail": "bool",
1478+
"documentation": {"kind": "markdown", "value": "```rescript\ntest: bool\n```\n\n```rescript\ntype someTyp = {test: bool}\n```"}
1479+
}]
1480+

0 commit comments

Comments
 (0)