Skip to content
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

chore: Backport changes from Metals #19592

Merged
merged 1 commit into from
Feb 2, 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the case completion will only appear when there are no other candidates ? I think we can go one step further and make case keyword to always be added to the list. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here scalameta/metals#5346 (comment) we decided to only show case if there are no other completions

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",
)

Loading