File tree 2 files changed +42
-8
lines changed
src/main/dotty/tools/pc/completions
test/dotty/tools/pc/tests/completion
2 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -164,13 +164,17 @@ object CaseKeywordCompletion:
164
164
(si, label)
165
165
}
166
166
}
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
+
174
178
includeExhaustive match
175
179
// In `List(foo).map { cas@@} we want to provide also `case (exhaustive)` completion
176
180
// which works like exhaustive match.
@@ -447,6 +451,20 @@ class CompletionValueGenerator(
447
451
end if
448
452
end labelForCaseMember
449
453
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
+
450
468
def toCompletionValue (
451
469
denot : Denotation ,
452
470
label : String ,
Original file line number Diff line number Diff line change @@ -542,7 +542,9 @@ class CompletionCaseSuite extends BaseCompletionSuite:
542
542
| ca@@
543
543
| }
544
544
|}""" .stripMargin,
545
- " "
545
+ """
546
+ |case
547
+ |""" .stripMargin
546
548
)
547
549
548
550
@ Test def `private-member-2` =
@@ -722,3 +724,17 @@ class CompletionCaseSuite extends BaseCompletionSuite:
722
724
|""" .stripMargin,
723
725
" case (Int, Int) => scala" ,
724
726
)
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