From f0a9ca712a26defb6aa529768721718e5c7c8cad Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 27 Mar 2025 18:33:34 +0100 Subject: [PATCH] bugfix: Fix issues with annotations not detected Fixes https://github.com/scalameta/metals/issues/6823 Not sure why tree.mods.annotations is sometimes empty, but I couldn't find a reason after landing in a rabbit hole. --- .../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 5fa7e921ba01..42e76dfeb114 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala @@ -40,6 +40,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*/