From 495c4c80b2a771ab796ea509c39988d9102cbc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zieli=C5=84ski=20Patryk?= <75637004+zielinsky@users.noreply.github.com> Date: Wed, 2 Jul 2025 13:18:01 +0200 Subject: [PATCH] fix: Inconsistent annotation tooltips (#23454) Fix: https://github.com/scalameta/metals/issues/7531 [Cherry-picked d109a39e02ea2eb09097c91e19f1936524df296b] --- .../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 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 + )