Skip to content

Backport "chore: Backport changes from Metals" to LTS #20880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
)