From def6fb62e6ed0efca7c5ebfd104e7e6330399e80 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 28 Mar 2025 08:49:02 +0100 Subject: [PATCH] bugfix: Fix issues with annotations not detected (#22878) [Cherry-picked d519790da2041ffab419749c0c49588bbb71db26] --- .../src/main/dotty/tools/pc/PcCollector.scala | 6 +++--- .../pc/tests/tokens/SemanticTokensSuite.scala | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala index f3fd7c8738d5..d145272ba01d 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala @@ -160,7 +160,7 @@ trait PcCollector[T]: def collectEndMarker = EndMarker.getPosition(df, pos, sourceText).map: collect(EndMarker(df.symbol), _) - val annots = collectTrees(df.mods.annotations) + val annots = collectTrees(df.symbol.annotations.map(_.tree)) val traverser = new PcCollector.DeepFolderWithParent[Set[T]]( collectNamesWithParent @@ -215,8 +215,8 @@ trait PcCollector[T]: * @<>("") * def params() = ??? */ - case mdf: MemberDef if mdf.mods.annotations.nonEmpty => - val trees = collectTrees(mdf.mods.annotations) + case mdf: MemberDef if mdf.symbol.annotations.nonEmpty => + val trees = collectTrees(mdf.symbol.annotations.map(_.tree)) val traverser = new PcCollector.DeepFolderWithParent[Set[T]]( collectNamesWithParent diff --git a/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala index 9f8d82020806..aebdf7f6c04e 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala @@ -36,6 +36,24 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite: |""".stripMargin ) + @Test def `metals-6823` = + check( + s"""|package <>/*namespace*/ + | + | @<
>/*class*/ def <>/*method,definition*/(): <>/*class,abstract*/ = + | val <>/*variable,definition,readonly*/ = <>/*class*/(1, 2, 3) + | <>/*method*/(<>/*variable,readonly*/) + | + |@<
>/*class*/ def <>/*method,definition*/(): <>/*class,abstract*/ = + | val <>/*variable,definition,readonly*/ = <>/*class*/(1, 2, 3) + | <>/*method*/(<>/*variable,readonly*/) + | + |@<
>/*class*/ def <>/*method,definition*/(): <>/*class,abstract*/ = + | val <>/*variable,definition,readonly*/ = <>/*class*/(1, 2, 3) + | <>/*method*/(<>/*variable,readonly*/) + |""".stripMargin + ) + @Test def `Comment(Single-Line, Multi-Line)` = check( s"""|package <>/*namespace*/