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

bugfix: completion in args in generic method w/ default args #7182

Merged
merged 1 commit into from
Feb 3, 2025
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 @@ -21,8 +21,10 @@ trait ArgCompletions { this: MetalsGlobal =>
val funPos = apply.fun.pos
val method: Tree = typedTreeAt(funPos) match {
// Functions calls with default arguments expand into this form
case Apply(Block(defParams, app @ (_: Apply | _: Select)), _)
if defParams.forall(p => p.isInstanceOf[ValDef]) =>
case Apply(
Block(defParams, app @ (_: Apply | _: Select | _: TypeApply)),
_
) if defParams.forall(p => p.isInstanceOf[ValDef]) =>
app
case New(c) => c
case t => t
Expand Down
23 changes: 23 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionArgSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,29 @@ class CompletionArgSuite extends BaseCompletionSuite {
topLines = Some(3)
)

check(
"default-args8",
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we have a similar issue in Scala 3, It might be somewhere around https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/completions/NamedArgCompletions.scala#L63

but for now you could tag it:

Suggested change
"default-args8",
"default-args8".tag(IgnoreScala3),

Copy link
Contributor Author

@harpocrates harpocrates Feb 2, 2025

Choose a reason for hiding this comment

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

Hmmm... weird output from Scala 3. Not exactly the same issue since it still provides reasonable completions, but it is missing just snd. Glanced through the Scala 3 codepath for 5 minutes, but I don't immediately see why.

I put in a compat just to at least record the fact that Scala 3 is currently producing some of the arg completions (much better than the previous Scala 2 empty behaviour). Hopefully if someone else fixes this at some point, they'll be able to just remove compat and my TODO next to it.

Let me know if you prefer to just tag IgnoreScala3

Copy link
Contributor

Choose a reason for hiding this comment

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

Raised an issue to not forget about this #7188

"""|trait Foo {
| def bar[A](fst: A, snd: Int, thd: Int = 23)
|}
|object Main {
| def foo: Foo = ???
| foo.bar(123, @@)
|}
|""".stripMargin,
"""|snd = : Int
|thd = : Int
|""".stripMargin,
topLines = Some(2),
compat = Map(
// TODO: this isn't right, we should see `snd = : Int` here as well
">=3.3.1" ->
"""|thd = : Int
|Main `default-args8`
|""".stripMargin
)
)

checkSnippet( // see: https://github.com/scalameta/metals/issues/2400
"explicit-dollar",
"""
Expand Down
Loading