Skip to content

Commit 9200b7e

Browse files
kasiaMarekKordyjan
authored andcommitted
bugfix: highlight enum cases correctly
[Cherry-picked aca2503]
1 parent 6468e1b commit 9200b7e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Diff for: presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala

+7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ abstract class PcCollector[T](
194194
case (df: NamedDefTree) :: _
195195
if df.nameSpan.contains(pos.span) && !isGeneratedGiven(df) =>
196196
Some(symbolAlternatives(df.symbol), pos.withSpan(df.nameSpan))
197+
/* enum cases with params
198+
* enum Foo:
199+
* case B@@ar[A](i: A)
200+
*/
201+
case (df: NamedDefTree) :: Template(_, _, self, _) :: _
202+
if (df.name == nme.apply || df.name == nme.unapply) && df.nameSpan.isZeroExtent =>
203+
Some(symbolAlternatives(self.tpt.symbol), self.sourcePos)
197204
/**
198205
* For traversing annotations:
199206
* @JsonNo@@tification("")

Diff for: presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala

+20
Original file line numberDiff line numberDiff line change
@@ -998,3 +998,23 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite:
998998
| def double2(ys: List[EF]) = <<xs>> ++ ys
999999
|end extension""".stripMargin
10001000
)
1001+
1002+
@Test def `enum-cases` =
1003+
check(
1004+
"""|enum MyOption:
1005+
| case <<My@@Some>>(value: Int)
1006+
| case MyNone
1007+
|
1008+
|val alpha = MyOption.<<MySome>>(1)
1009+
|""".stripMargin
1010+
)
1011+
1012+
@Test def `enum-cases2` =
1013+
check(
1014+
"""|enum MyOption:
1015+
| case <<My@@Some>>[U](value: U)
1016+
| case MyNone
1017+
|
1018+
|val alpha = MyOption.<<MySome>>(1)
1019+
|""".stripMargin,
1020+
)

0 commit comments

Comments
 (0)