From 4c33849a0cba81d1b925997fe8aba74a385f0c89 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Mon, 7 Aug 2023 12:35:07 +0200 Subject: [PATCH] bugfix: highlight enum cases correctly --- .../scala/meta/internal/pc/PcCollector.scala | 7 +++++++ .../Scala3DocumentHighlightSuite.scala | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala index f2325935812..79d231038d3 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala @@ -195,6 +195,13 @@ abstract class PcCollector[T]( case (df: NamedDefTree) :: _ if df.nameSpan.contains(pos.span) && !isGeneratedGiven(df) => Some(symbolAlternatives(df.symbol), pos.withSpan(df.nameSpan)) + /* enum cases with params + * enum Foo: + * case B@@ar[A](i: A) + */ + case (df: NamedDefTree) :: Template(_, _, self, _) :: _ + if (df.name == nme.apply || df.name == nme.unapply) && df.nameSpan.isZeroExtent => + Some(symbolAlternatives(self.tpt.symbol), self.sourcePos) /** * For traversing annotations: * @JsonNo@@tification("") diff --git a/tests/cross/src/test/scala/tests/highlight/Scala3DocumentHighlightSuite.scala b/tests/cross/src/test/scala/tests/highlight/Scala3DocumentHighlightSuite.scala index 13136a3ce76..09a15a10147 100644 --- a/tests/cross/src/test/scala/tests/highlight/Scala3DocumentHighlightSuite.scala +++ b/tests/cross/src/test/scala/tests/highlight/Scala3DocumentHighlightSuite.scala @@ -247,4 +247,24 @@ class Scala3DocumentHighlightSuite extends BaseDocumentHighlightSuite { |end extension""".stripMargin, ) + check( + "enum-cases".tag(IgnoreScala2), + """|enum MyOption: + | case <>(value: Int) + | case MyNone + | + |val alpha = MyOption.<>(1) + |""".stripMargin, + ) + + check( + "enum-cases2".tag(IgnoreScala2), + """|enum MyOption: + | case <>[U](value: U) + | case MyNone + | + |val alpha = MyOption.<>(1) + |""".stripMargin, + ) + }