Skip to content

Commit 1ef9de0

Browse files
kasiaMarektgodzik
authored andcommitted
fix: go to definition and hover for named args in pattern match
Co-Authored-By: Prince <[email protected]> [Cherry-picked 47b6a29]
1 parent 39b3db3 commit 1ef9de0

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ object MetalsInteractive:
120120
// For a named arg, find the target `DefDef` and jump to the param
121121
case NamedArg(name, _) :: Apply(fn, _) :: _ =>
122122
val funSym = fn.symbol
123-
if funSym.is(Synthetic) && funSym.owner.is(CaseClass) then
124-
val sym = funSym.owner.info.member(name).symbol
123+
lazy val owner = funSym.owner.companionClass
124+
if funSym.is(Synthetic) && owner.is(CaseClass) then
125+
val sym = owner.info.member(name).symbol
125126
List((sym, sym.info, None))
126127
else
127128
val paramSymbol =
@@ -130,6 +131,13 @@ object MetalsInteractive:
130131
val sym = paramSymbol.getOrElse(fn.symbol)
131132
List((sym, sym.info, None))
132133

134+
case NamedArg(name, _) :: UnApply(s, _, _) :: _ =>
135+
lazy val owner = s.symbol.owner.companionClass
136+
if s.symbol.is(Synthetic) && owner.is(CaseClass) then
137+
val sym = owner.info.member(name).symbol
138+
List((sym, sym.info, None))
139+
else Nil
140+
133141
case (_: untpd.ImportSelector) :: (imp: Import) :: _ =>
134142
importedSymbols(imp, _.span.contains(pos.span)).map(sym =>
135143
(sym, sym.info, None)

presentation-compiler/test/dotty/tools/pc/tests/definition/PcDefinitionSuite.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,34 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
639639
| export scala.collection.immutable.V/*scala/collection/immutable/Vector. Vector.scala*/@@ector
640640
|""".stripMargin
641641
)
642+
643+
@Test def i7763 =
644+
check(
645+
"""|case class MyItem(<<name>>: String)
646+
|
647+
|def handle(item: MyItem) =
648+
| item match {
649+
| case MyItem(na@@me = n2) => println(n2)
650+
| }
651+
|""".stripMargin
652+
)
653+
654+
@Test def `i7763-neg` =
655+
check(
656+
"""|object MyItem:
657+
| def unapply(name: String): Option[Int] = ???
658+
|
659+
|def handle(item: String) =
660+
| item match {
661+
| case MyItem(na@@me = n2) => println(n2)
662+
| }
663+
|""".stripMargin
664+
)
665+
666+
@Test def `i7763-apply` =
667+
check(
668+
"""|case class MyItem(<<name>>: String)
669+
|
670+
|def handle(item: String) = MyItem(na@@me = item)
671+
|""".stripMargin
672+
)

presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,3 +870,15 @@ class HoverTermSuite extends BaseHoverSuite:
870870
|""".stripMargin,
871871
"val aa: Int".hover
872872
)
873+
874+
@Test def i7763 =
875+
check(
876+
"""|case class MyItem(name: String)
877+
|
878+
|def handle(item: MyItem) =
879+
| item match {
880+
| case MyItem(na@@me = n2) => println(n2)
881+
| }
882+
|""".stripMargin,
883+
"val name: String".hover
884+
)

0 commit comments

Comments
 (0)