Skip to content

Commit

Permalink
bugfix: Signature help in Scala 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Oct 9, 2023
1 parent d2ccce2 commit 2c75be6
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SignatureHelpProvider(val compiler: MetalsGlobal) {
o.info.member(compiler.nme.apply).alternatives
case o: ClassSymbol =>
o.info.member(compiler.termNames.CONSTRUCTOR).alternatives
case m: MethodSymbol =>
case m: MethodSymbol if !m.isLocalToBlock =>
m.owner.info.member(symbol.name).alternatives
case _ =>
symbol.alternatives
Expand Down Expand Up @@ -359,6 +359,14 @@ class SignatureHelpProvider(val compiler: MetalsGlobal) {
tree match {
case UnApply(qual, _) =>
qual.symbol
// Special case: a method call with named arguments like `foo(a = 1, b = 2)` gets desugared into the following:
// {
// val x$1 = 1
// val x$2 = 2
// foo(x$1, x$2)
// }
case Apply(Block(_, expr), _) =>
expr.symbol
case _ =>
NoSymbol
}
Expand Down
140 changes: 140 additions & 0 deletions tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -925,4 +925,144 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite {
|""".stripMargin,
)

check(
"default-args".tag(
IgnoreScalaVersion.for3LessThan(
"3.4.0-RC1-bin-20231001-09ea77e-NIGHTLY"
)
),
"""
|object Main {
| def foo() = {
| def deployment(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment(@@)
| }
|}
|""".stripMargin,
"""|deployment(fst: String, snd: Int = ...): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin,
compat = Map(
"3" ->
"""|deployment(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin
),
)

check(
"default-args2",
"""
|object Main {
| def deployment(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment(@@)
|}
|""".stripMargin,
"""|deployment(fst: String, snd: Int = 1): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin,
compat = Map(
"3" ->
"""|deployment(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin
),
)

check(
"default-args3",
"""
|object Main {
| def deployment(str: String)(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment("str")(
| @@
| )
|}
|""".stripMargin,
"""|deployment(fst: String, snd: Int = ...): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin,
compat = Map(
"3" ->
"""|deployment(str: String)(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin
),
)

check(
"default-args4",
"""
|object Main {
| def deployment(str: String)(opt: Option[Int])(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment("str")(None)(
| @@
| )
|}
|""".stripMargin,
"""|deployment(fst: String, snd: Int = ...): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin,
compat = Map(
"3" ->
"""|deployment(str: String)(opt: Option[Int])(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin
),
)

check(
"default-args5",
"""
|object Main {
| def deployment(str: String)(opt: Option[Int] = None)(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment("str")(
| @@
| )
|}
|""".stripMargin,
"""|deployment(str: String)(opt: Option[Int] = None)(fst: String, snd: Int = 1): Option[Int]
| ^^^^^^^^^^^^^^^^^^^^^^^
|""".stripMargin,
compat = Map(
"3" ->
"""|deployment(str: String)(opt: Option[Int])(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^^^^^^
|""".stripMargin
),
)

check(
"default-args6".tag(IgnoreScala2),
"""
|object Main {
| def deployment(using str: String)(
| fst: String,
| snd: Int = 1,
| ): Option[Int] = ???
| val abc = deployment(using "str")(
| @@
| )
|}
|""".stripMargin,
"""|deployment(using str: String)(fst: String, snd: Int): Option[Int]
| ^^^^^^^^^^^
|""".stripMargin,
)

}

0 comments on commit 2c75be6

Please sign in to comment.