Skip to content

Commit 93a2924

Browse files
committed
bugfix: Case completions for tuple type
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.
1 parent 94f5cdb commit 93a2924

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

presentation-compiler/src/main/dotty/tools/pc/completions/MatchCaseCompletions.scala

+17-16
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,26 @@ object CaseKeywordCompletion:
9797
selectorSym
9898
)
9999
then
100-
val label =
101-
if patternOnly.isEmpty then s"case ${parents.selector.show} =>"
102-
else parents.selector.show
103-
List(
104-
CompletionValue.CaseKeyword(
105-
selectorSym,
106-
label,
107-
Some(
108-
if patternOnly.isEmpty then
100+
if patternOnly.isEmpty then
101+
val selectorTpe = parents.selector.show
102+
val tpeLabel =
103+
if !selectorTpe.contains("x$1") then selectorTpe
104+
else selector.symbol.info.show
105+
val label = s"case ${tpeLabel} =>"
106+
List(
107+
CompletionValue.CaseKeyword(
108+
selectorSym,
109+
label,
110+
Some(
109111
if config.isCompletionSnippetsEnabled() then "case ($0) =>"
110112
else "case () =>"
111-
else if config.isCompletionSnippetsEnabled() then "($0)"
112-
else "()"
113-
),
114-
Nil,
115-
range = Some(completionPos.toEditRange),
116-
command = config.parameterHintsCommand().asScala
113+
),
114+
Nil,
115+
range = Some(completionPos.toEditRange),
116+
command = config.parameterHintsCommand().asScala,
117+
)
117118
)
118-
)
119+
else Nil
119120
else
120121
val result = ListBuffer.empty[SymbolImport]
121122
val isVisited = mutable.Set.empty[Symbol]

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCaseSuite.scala

+24
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,27 @@ class CompletionCaseSuite extends BaseCompletionSuite:
698698
|case Dog => test.O.Animal
699699
|""".stripMargin,
700700
)
701+
@Test def `for-comp` =
702+
check(
703+
"""|object A {
704+
| val a = for {
705+
| foo <- List("a", "b", "c")
706+
| abc = println("Print!")
707+
| } yield bar@@
708+
|
709+
|}
710+
|""".stripMargin,
711+
"",
712+
)
713+
714+
@Test def `lambda-case-tuple` =
715+
check(
716+
"""|object A {
717+
| val a = List((1,2)).foreach {
718+
| case (a,b) => println(a)
719+
| case@@
720+
| }
721+
|}
722+
|""".stripMargin,
723+
"case (Int, Int) => scala",
724+
)

0 commit comments

Comments
 (0)