Skip to content

Commit

Permalink
Backport "bugfix: [metals] Case completions for tuple type" to LTS (#…
Browse files Browse the repository at this point in the history
…20755)

Backports #18751 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 23, 2024
2 parents b1526f2 + 6f21c2d commit abae804
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 abae804

Please sign in to comment.