Skip to content

Commit d109a39

Browse files
authored
fix: Inconsistent annotation tooltips (#23454)
Fix: scalameta/metals#7531
1 parent 542ca19 commit d109a39

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

‎compiler/src/dotty/tools/dotc/ast/NavigateAST.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ object NavigateAST {
141141
case _ =>
142142
val iterator = p match
143143
case defdef: DefTree[?] =>
144-
p.productIterator ++ defdef.mods.productIterator
144+
val mods = defdef.mods
145+
val annotations = defdef.symbol.annotations.filter(_.tree.span.contains(span)).map(_.tree)
146+
p.productIterator ++ annotations ++ mods.productIterator
145147
case _ =>
146148
p.productIterator
147149
childPath(iterator, p :: path)

‎presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDefnSuite.scala

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,51 @@ class HoverDefnSuite extends BaseHoverSuite:
279279
|```
280280
|""".stripMargin
281281
)
282+
283+
@Test def `annotation` =
284+
check(
285+
"""|
286+
|@ma@@in
287+
|def example() =
288+
| println("test")
289+
|""".stripMargin,
290+
"""|```scala
291+
|def this(): main
292+
|```""".stripMargin.hover
293+
)
294+
295+
@Test def `annotation-2` =
296+
check(
297+
"""|
298+
|@ma@@in
299+
|def example() =
300+
| List("test")
301+
|""".stripMargin,
302+
"""|```scala
303+
|def this(): main
304+
|```""".stripMargin.hover
305+
)
306+
307+
@Test def `annotation-3` =
308+
check(
309+
"""|
310+
|@ma@@in
311+
|def example() =
312+
| Array("test")
313+
|""".stripMargin,
314+
"""|```scala
315+
|def this(): main
316+
|```""".stripMargin.hover
317+
)
318+
319+
@Test def `annotation-4` =
320+
check(
321+
"""|
322+
|@ma@@in
323+
|def example() =
324+
| Array(1, 2)
325+
|""".stripMargin,
326+
"""|```scala
327+
|def this(): main
328+
|```""".stripMargin.hover
329+
)

0 commit comments

Comments
 (0)