diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/MatchCaseCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/MatchCaseCompletions.scala index 04a0a931bd26..edb489228d92 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/MatchCaseCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/MatchCaseCompletions.scala @@ -164,13 +164,17 @@ object CaseKeywordCompletion: (si, label) } } - val caseItems = res.map((si, label) => - completionGenerator.toCompletionValue( - si.sym, - label, - autoImportsGen.renderImports(si.importSel.toList) - ) - ) + val caseItems = + if res.isEmpty then completionGenerator.caseKeywordOnly + else + res.map((si, label) => + completionGenerator.toCompletionValue( + si.sym, + label, + autoImportsGen.renderImports(si.importSel.toList), + ) + ) + includeExhaustive match // In `List(foo).map { cas@@} we want to provide also `case (exhaustive)` completion // which works like exhaustive match. @@ -441,6 +445,20 @@ class CompletionValueGenerator( end if end labelForCaseMember + def caseKeywordOnly: List[CompletionValue.Keyword] = + if patternOnly.isEmpty then + val label = "case" + val suffix = + if clientSupportsSnippets then " $0 =>" + else " " + List( + CompletionValue.Keyword( + label, + Some(label + suffix), + ) + ) + else Nil + def toCompletionValue( denot: Denotation, label: String, diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCaseSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCaseSuite.scala index 96a7cff9e73c..7a00c0397644 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCaseSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionCaseSuite.scala @@ -542,7 +542,9 @@ class CompletionCaseSuite extends BaseCompletionSuite: | ca@@ | } |}""".stripMargin, - "" + """ + |case + |""".stripMargin ) @Test def `private-member-2` = @@ -722,3 +724,17 @@ class CompletionCaseSuite extends BaseCompletionSuite: |""".stripMargin, "case (Int, Int) => scala", ) + + @Test def `keyword-only` = + check( + """ + |sealed trait Alpha + |object A { + | List.empty[Alpha].groupBy{ + | ca@@ + | } + |} + |""".stripMargin, + "case", + ) +