From dd904d2dcec3234e3c1ab35b7cc57ff731eb15cf Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 19 Sep 2022 16:10:08 +0200 Subject: [PATCH] bugfix: Traverse annotations in NavigateAST Previously, we wouldn't find any symbols inside annotations. Now we do find them correctly. I wonder if this should also be done in some other places such as TreeAccumulator, I can follow up later with that since it might be a bit more dangerous change --- compiler/src/dotty/tools/dotc/ast/NavigateAST.scala | 7 ++++++- .../test/dotty/tools/languageserver/HoverTest.scala | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala index bcedc4dfa50b..054ffe66f323 100644 --- a/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala +++ b/compiler/src/dotty/tools/dotc/ast/NavigateAST.scala @@ -111,7 +111,12 @@ object NavigateAST { p.forceIfLazy case _ => } - childPath(p.productIterator, p :: path) + val iterator = p match + case defdef: DefTree[?] => + p.productIterator ++ defdef.mods.productIterator + case _ => + p.productIterator + childPath(iterator, p :: path) } else { p match { diff --git a/language-server/test/dotty/tools/languageserver/HoverTest.scala b/language-server/test/dotty/tools/languageserver/HoverTest.scala index bbfec815e79a..a2196f4a71f3 100644 --- a/language-server/test/dotty/tools/languageserver/HoverTest.scala +++ b/language-server/test/dotty/tools/languageserver/HoverTest.scala @@ -244,4 +244,10 @@ class HoverTest { .hover(m1 to m2, hoverContent("Double")) .hover(m3 to m4, hoverContent("Double")) } + + @Test def annotation: Unit = { + code"""|@${m1}deprecated${m2} def ${m3}x${m4} = 42.0""" + .hover(m1 to m2, hoverContent("deprecated")) + .hover(m3 to m4, hoverContent("Double")) + } }