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.
@@ -441,6 +445,20 @@ class CompletionValueGenerator(
441
445
end if
442
446
end labelForCaseMember
443
447
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
+
444
462
def toCompletionValue (
445
463
denot : Denotation ,
446
464
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