Skip to content

Commit 11e1751

Browse files
jkcieslukWojciechMazur
authored andcommitted
chore: Backport changes from Metals (#19592)
backports scalameta/metals#5346 [Cherry-picked f15bbda]
1 parent 0bec5ad commit 11e1751

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

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

+25-7
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,17 @@ object CaseKeywordCompletion:
164164
(si, label)
165165
}
166166
}
167-
val caseItems = res.map((si, label) =>
168-
completionGenerator.toCompletionValue(
169-
si.sym,
170-
label,
171-
autoImportsGen.renderImports(si.importSel.toList)
172-
)
173-
)
167+
val caseItems =
168+
if res.isEmpty then completionGenerator.caseKeywordOnly
169+
else
170+
res.map((si, label) =>
171+
completionGenerator.toCompletionValue(
172+
si.sym,
173+
label,
174+
autoImportsGen.renderImports(si.importSel.toList),
175+
)
176+
)
177+
174178
includeExhaustive match
175179
// In `List(foo).map { cas@@} we want to provide also `case (exhaustive)` completion
176180
// which works like exhaustive match.
@@ -447,6 +451,20 @@ class CompletionValueGenerator(
447451
end if
448452
end labelForCaseMember
449453

454+
def caseKeywordOnly: List[CompletionValue.Keyword] =
455+
if patternOnly.isEmpty then
456+
val label = "case"
457+
val suffix =
458+
if clientSupportsSnippets then " $0 =>"
459+
else " "
460+
List(
461+
CompletionValue.Keyword(
462+
label,
463+
Some(label + suffix),
464+
)
465+
)
466+
else Nil
467+
450468
def toCompletionValue(
451469
denot: Denotation,
452470
label: String,

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ class CompletionCaseSuite extends BaseCompletionSuite:
542542
| ca@@
543543
| }
544544
|}""".stripMargin,
545-
""
545+
"""
546+
|case
547+
|""".stripMargin
546548
)
547549

548550
@Test def `private-member-2` =
@@ -722,3 +724,17 @@ class CompletionCaseSuite extends BaseCompletionSuite:
722724
|""".stripMargin,
723725
"case (Int, Int) => scala",
724726
)
727+
728+
@Test def `keyword-only` =
729+
check(
730+
"""
731+
|sealed trait Alpha
732+
|object A {
733+
| List.empty[Alpha].groupBy{
734+
| ca@@
735+
| }
736+
|}
737+
|""".stripMargin,
738+
"case",
739+
)
740+

0 commit comments

Comments
 (0)