Skip to content

Commit 3cd07b6

Browse files
committed
Navigate the AST within AnnotatedType and ImportType
Related to #13624
1 parent 968dd1b commit 3cd07b6

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import core.Contexts._
55
import core.Decorators._
66
import util.Spans._
77
import Trees.{MemberDef, DefTree, WithLazyField}
8+
import dotty.tools.dotc.core.Annotations.ConcreteAnnotation
9+
import dotty.tools.dotc.core.Types.AnnotatedType
10+
import dotty.tools.dotc.core.Types.ImportType
811

912
/** Utility functions to go from typed to untyped ASTs */
1013
// TODO: Handle trees with mixed source files
@@ -98,7 +101,20 @@ object NavigateAST {
98101
}
99102
childPath(p.productIterator, p :: path)
100103
}
101-
else path
104+
else {
105+
p match {
106+
case t: untpd.TypeTree =>
107+
t.typeOpt match {
108+
case ann: AnnotatedType =>
109+
childPath(ann.annot.tree.productIterator, path)
110+
case imp: ImportType =>
111+
childPath(imp.expr.productIterator, path)
112+
case _ =>
113+
path
114+
}
115+
case _ => path
116+
}
117+
}
102118
singlePath(from, Nil)
103119
}
104120
}

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,4 +895,21 @@ class CompletionTest {
895895
@Test def i12465_hkt_alias: Unit =
896896
code"""???.asInstanceOf[Seq].${m1}""".withSource
897897
.completion(m1, Set())
898-
}
898+
899+
@Test def i13624_annotType: Unit =
900+
code"""|class MyAnnotation extends annotation.StaticAnnotation
901+
|val x = 1: @MyAnnot${m1}
902+
|type X = Int @MyAnnot${m2}""".withSource
903+
.completion(
904+
m1,
905+
Set(
906+
("MyAnnotation", Class, "MyAnnotation"),
907+
("MyAnnotation", Module, "MyAnnotation")
908+
)
909+
).completion(
910+
m2,
911+
Set(
912+
("MyAnnotation", Class, "MyAnnotation"),
913+
("MyAnnotation", Module, "MyAnnotation")
914+
)
915+
)}

0 commit comments

Comments
 (0)