Skip to content

Commit 96e0477

Browse files
Backport "fix: go to definition and hover for named args in pattern match" to 3.7.4 (#24004)
Backports #23956 to the 3.7.4. PR submitted by the release tooling.
2 parents 0f537fb + bc67e27 commit 96e0477

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
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/src/main/dotty/tools/pc/completions/CompletionAffix.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ case class CompletionAffix(
5656
private def loopPrefix(prefixes: List[PrefixKind]): String =
5757
prefixes match
5858
case PrefixKind.New :: tail => "new " + loopPrefix(tail)
59+
case PrefixKind.Using :: tail => "using " + loopPrefix(tail)
5960
case _ => ""
6061

6162
/**
@@ -87,7 +88,7 @@ enum SuffixKind:
8788
case Brace, Bracket, Template, NoSuffix
8889

8990
enum PrefixKind:
90-
case New
91+
case New, Using
9192

9293
type Suffix = Affix[SuffixKind]
9394
type Prefix = Affix[PrefixKind]

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

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,15 @@ class HoverTermSuite extends BaseHoverSuite:
926926
|""".stripMargin,
927927
"val aa: Int".hover
928928
)
929+
930+
@Test def i7763 =
931+
check(
932+
"""|case class MyItem(name: String)
933+
|
934+
|def handle(item: MyItem) =
935+
| item match {
936+
| case MyItem(na@@me = n2) => println(n2)
937+
| }
938+
|""".stripMargin,
939+
"val name: String".hover
940+
)

0 commit comments

Comments
 (0)