File tree Expand file tree Collapse file tree 2 files changed +42
-8
lines changed
src/main/dotty/tools/pc/completions
test/dotty/tools/pc/tests/completion Expand file tree Collapse file tree 2 files changed +42
-8
lines changed Original file line number Diff line number Diff 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.
@@ -441,6 +445,20 @@ class CompletionValueGenerator(
441445 end if
442446 end labelForCaseMember
443447
448+ def caseKeywordOnly : List [CompletionValue .Keyword ] =
449+ if patternOnly.isEmpty then
450+ val label = " case"
451+ val suffix =
452+ if clientSupportsSnippets then " $0 =>"
453+ else " "
454+ List (
455+ CompletionValue .Keyword (
456+ label,
457+ Some (label + suffix),
458+ )
459+ )
460+ else Nil
461+
444462 def toCompletionValue (
445463 denot : Denotation ,
446464 label : String ,
Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments