diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/PcDefinitionProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/PcDefinitionProvider.scala index e92f54212a8..7d5284e56e5 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/PcDefinitionProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/PcDefinitionProvider.scala @@ -26,8 +26,7 @@ class PcDefinitionProvider(val compiler: MetalsGlobal, params: OffsetParams) { if ( tree.symbol == null || tree.symbol == NoSymbol || - tree.symbol.isErroneous || - tree.symbol.isSynthetic + tree.symbol.isErroneous ) { DefinitionResultImpl.empty } else if (tree.symbol.hasPackageFlag) { @@ -43,7 +42,7 @@ class PcDefinitionProvider(val compiler: MetalsGlobal, params: OffsetParams) { DefinitionResultImpl( semanticdbSymbol(tree.symbol), ju.Collections.singletonList( - new Location(params.uri().toString(), tree.symbol.pos.toLSP) + new Location(params.uri().toString(), tree.symbol.pos.focus.toLSP) ) ) } else { diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/PcDefinitionProvider.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/PcDefinitionProvider.scala index 862773aa2cd..bac6fe49003 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/PcDefinitionProvider.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/PcDefinitionProvider.scala @@ -130,13 +130,15 @@ class PcDefinitionProvider( case (imp: Import) :: _ => importedSymbols(imp, _.span.contains(pos.span)) - // For constructor calls, return the `` that was selected - case _ :: (_: New) :: (select: Select) :: _ => - List(select.symbol) - // wildcard param case head :: _ if (head.symbol.is(Param) && head.symbol.is(Synthetic)) => - Nil + List(head.symbol) + + case (head @ Select(target, name)) :: _ + if head.symbol.is(Synthetic) && name == StdNames.nme.apply => + val sym = target.symbol + if sym.is(Synthetic) && sym.is(Module) then List(sym.companionClass) + else List(target.symbol) case head :: tl => if head.symbol.is(Synthetic) then enclosingSymbols(tl, pos, indexed) diff --git a/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala b/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala index 1bbcb8aa5ee..1ed0c8e75c5 100644 --- a/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala @@ -30,13 +30,25 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { """| |object Main { | for { - | <> <- List(1) + | <<>>x <- List(1) | y <- 1.to(x) | z = y + x | if y < @@x | } yield y |} - |""".stripMargin + |""".stripMargin, + compat = Map( + "3" -> + """|object Main { + | for { + | <> <- List(1) + | y <- 1.to(x) + | z = y + x + | if y < x + | } yield y + |} + |""".stripMargin + ) ) check( @@ -225,7 +237,7 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { "named-arg-local", """| |object Main { - | <> + | def <<>>foo(arg: Int): Unit = () | | foo(a@@rg = 42) |} @@ -302,9 +314,33 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { "eta", """| |object Main { - | List(1).map(@@_ + 2) + | List(1).map(<<>>@@_ + 2) |} - |""".stripMargin + |""".stripMargin, + compat = Map( + "3" -> + """| + |object Main { + | List(1).map(@@_ + 2) + |} + |""".stripMargin + ) + ) + + check( + "eta-2", + """| + |object Main { + | List(1).foldLeft(0)(_ + <<>>@@_) + |} + |""".stripMargin, + compat = Map( + "3" -> + """|object Main { + | List(1).foldLeft(0)(_ + _) + |} + |""".stripMargin + ) ) check( @@ -351,4 +387,46 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { |} |""".stripMargin ) + + check( + "synthetic-definition-case-class", + """| + |class Main { + | case class <<>>User(name: String, age: Int) + | def hello(u: User): Unit = () + | hello(Us@@er()) + |} + |""".stripMargin, + compat = Map( + "3" -> + """| + |class Main { + | case class <>(name: String, age: Int) + | def hello(u: User): Unit = () + | hello(User()) + |} + |""".stripMargin + ) + ) + + check( + "synthetic-definition-class-constructor", + """| + |class Main { + | class <<>>User(name: String, age: Int) + | def hello(u: User): Unit = () + | hello(new Us@@er()) + |} + |""".stripMargin, + compat = Map( + "3" -> + """| + |class Main { + | class <>(name: String, age: Int) + | def hello(u: User): Unit = () + | hello(new Us@@er()) + |} + |""".stripMargin + ) + ) }