Skip to content

Commit

Permalink
chore: Backport changes from Metals (#19592)
Browse files Browse the repository at this point in the history
backports scalameta/metals#5346
[Cherry-picked f15bbda]
  • Loading branch information
jkciesluk authored and WojciechMazur committed Jun 30, 2024
1 parent 0bec5ad commit ddf24b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -447,6 +451,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ class CompletionCaseSuite extends BaseCompletionSuite:
| ca@@
| }
|}""".stripMargin,
""
"""
|case
|""".stripMargin
)

@Test def `private-member-2` =
Expand Down Expand Up @@ -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",
)

0 comments on commit ddf24b5

Please sign in to comment.