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 6a544fb3a6bc..466eb379ff48 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala @@ -255,3 +255,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 + )