From 2c75be6a2d86ac0e86436d9e083064c9302ddced Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Tue, 26 Sep 2023 09:48:58 +0200 Subject: [PATCH] bugfix: Signature help in Scala 2 --- .../internal/pc/SignatureHelpProvider.scala | 10 +- .../scala/tests/pc/SignatureHelpSuite.scala | 140 ++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala index 87579794dc2..d87771e22a6 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala @@ -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 @@ -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 } diff --git a/tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala b/tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala index 9df9f452782..c060fef7840 100644 --- a/tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/SignatureHelpSuite.scala @@ -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, + ) + }