Skip to content

Commit

Permalink
bugfix: Case completions for tuple type
Browse files Browse the repository at this point in the history
We shouldn't show case completions for tuple type if query doesn't match label.
Also, sometimes label contained x$1 symbol (eg. (x$1: (Int, Int)) @unchecked scala, which we don't want to show to the user.
  • Loading branch information
jkciesluk committed Oct 27, 2023
1 parent 94f5cdb commit 93a2924
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,26 @@ object CaseKeywordCompletion:
selectorSym
)
then
val label =
if patternOnly.isEmpty then s"case ${parents.selector.show} =>"
else parents.selector.show
List(
CompletionValue.CaseKeyword(
selectorSym,
label,
Some(
if patternOnly.isEmpty then
if patternOnly.isEmpty then
val selectorTpe = parents.selector.show
val tpeLabel =
if !selectorTpe.contains("x$1") then selectorTpe
else selector.symbol.info.show
val label = s"case ${tpeLabel} =>"
List(
CompletionValue.CaseKeyword(
selectorSym,
label,
Some(
if config.isCompletionSnippetsEnabled() then "case ($0) =>"
else "case () =>"
else if config.isCompletionSnippetsEnabled() then "($0)"
else "()"
),
Nil,
range = Some(completionPos.toEditRange),
command = config.parameterHintsCommand().asScala
),
Nil,
range = Some(completionPos.toEditRange),
command = config.parameterHintsCommand().asScala,
)
)
)
else Nil
else
val result = ListBuffer.empty[SymbolImport]
val isVisited = mutable.Set.empty[Symbol]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,27 @@ class CompletionCaseSuite extends BaseCompletionSuite:
|case Dog => test.O.Animal
|""".stripMargin,
)
@Test def `for-comp` =
check(
"""|object A {
| val a = for {
| foo <- List("a", "b", "c")
| abc = println("Print!")
| } yield bar@@
|
|}
|""".stripMargin,
"",
)

@Test def `lambda-case-tuple` =
check(
"""|object A {
| val a = List((1,2)).foreach {
| case (a,b) => println(a)
| case@@
| }
|}
|""".stripMargin,
"case (Int, Int) => scala",
)

0 comments on commit 93a2924

Please # to comment.