Skip to content

Commit d519790

Browse files
authored
bugfix: Fix issues with annotations not detected (#22878)
1 parent 701fa8a commit d519790

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ trait PcCollector[T]:
160160
def collectEndMarker =
161161
EndMarker.getPosition(df, pos, sourceText).map:
162162
collect(EndMarker(df.symbol), _)
163-
val annots = collectTrees(df.mods.annotations)
163+
val annots = collectTrees(df.symbol.annotations.map(_.tree))
164164
val traverser =
165165
new PcCollector.DeepFolderWithParent[Set[T]](
166166
collectNamesWithParent
@@ -215,8 +215,8 @@ trait PcCollector[T]:
215215
* @<<JsonNotification>>("")
216216
* def params() = ???
217217
*/
218-
case mdf: MemberDef if mdf.mods.annotations.nonEmpty =>
219-
val trees = collectTrees(mdf.mods.annotations)
218+
case mdf: MemberDef if mdf.symbol.annotations.nonEmpty =>
219+
val trees = collectTrees(mdf.symbol.annotations.map(_.tree))
220220
val traverser =
221221
new PcCollector.DeepFolderWithParent[Set[T]](
222222
collectNamesWithParent

presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala

+18
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
4040
|""".stripMargin
4141
)
4242

43+
@Test def `metals-6823` =
44+
check(
45+
s"""|package <<example>>/*namespace*/
46+
|
47+
| @<<main>>/*class*/ def <<main1>>/*method,definition*/(): <<Unit>>/*class,abstract*/ =
48+
| val <<array>>/*variable,definition,readonly*/ = <<Array>>/*class*/(1, 2, 3)
49+
| <<println>>/*method*/(<<array>>/*variable,readonly*/)
50+
|
51+
|@<<main>>/*class*/ def <<main2>>/*method,definition*/(): <<Unit>>/*class,abstract*/ =
52+
| val <<list>>/*variable,definition,readonly*/ = <<List>>/*class*/(1, 2, 3)
53+
| <<println>>/*method*/(<<list>>/*variable,readonly*/)
54+
|
55+
|@<<main>>/*class*/ def <<main3>>/*method,definition*/(): <<Unit>>/*class,abstract*/ =
56+
| val <<list>>/*variable,definition,readonly*/ = <<List>>/*class*/(1, 2, 3)
57+
| <<println>>/*method*/(<<list>>/*variable,readonly*/)
58+
|""".stripMargin
59+
)
60+
4361
@Test def `Comment(Single-Line, Multi-Line)` =
4462
check(
4563
s"""|package <<example>>/*namespace*/

0 commit comments

Comments
 (0)