Skip to content

Commit

Permalink
chore: Backport changes from Metals
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Feb 1, 2024
1 parent 95266f2 commit 9c1d5b6
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 @@ -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,
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 9c1d5b6

Please sign in to comment.