From 3cb5f31b362240fee6b06d0c1a203a0cc9f5a223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Zieli=C5=84ski?= Date: Mon, 30 Jun 2025 19:22:39 +0200 Subject: [PATCH] change mods to annotations --- .../dotty/tools/dotc/ast/NavigateAST.scala | 4 +- .../tools/pc/tests/hover/HoverDefnSuite.scala | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala index e77642a8e2b9..90bd9b7923ae 100644 --- a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala +++ b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala @@ -141,7 +141,9 @@ object NavigateAST { case _ => val iterator = p match case defdef: DefTree[?] => - p.productIterator ++ defdef.mods.productIterator + val mods = defdef.mods + val annotations = defdef.symbol.annotations.filter(_.tree.span.contains(span)).map(_.tree) + p.productIterator ++ annotations ++ mods.productIterator case _ => p.productIterator childPath(iterator, p :: path) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala index dae77cecc2a2..bdc3b4543383 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala @@ -279,3 +279,51 @@ class HoverDefnSuite extends BaseHoverSuite: |``` |""".stripMargin ) + + @Test def `annotation` = + check( + """| + |@ma@@in + |def example() = + | println("test") + |""".stripMargin, + """|```scala + |def this(): main + |```""".stripMargin.hover + ) + + @Test def `annotation-2` = + check( + """| + |@ma@@in + |def example() = + | List("test") + |""".stripMargin, + """|```scala + |def this(): main + |```""".stripMargin.hover + ) + + @Test def `annotation-3` = + check( + """| + |@ma@@in + |def example() = + | Array("test") + |""".stripMargin, + """|```scala + |def this(): main + |```""".stripMargin.hover + ) + + @Test def `annotation-4` = + check( + """| + |@ma@@in + |def example() = + | Array(1, 2) + |""".stripMargin, + """|```scala + |def this(): main + |```""".stripMargin.hover + )