File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
compiler/src/dotty/tools/dotc
language-server/test/dotty/tools/languageserver Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ object NavigateAST {
60
60
* the given `span`.
61
61
*/
62
62
def untypedPath (span : Span )(using Context ): List [Positioned ] =
63
- pathTo(span, ctx.compilationUnit.untpdTree)
63
+ pathTo(span, List ( ctx.compilationUnit.untpdTree) )
64
64
65
65
66
66
/** The reverse path from node `from` to the node that closest encloses `span`,
@@ -72,7 +72,7 @@ object NavigateAST {
72
72
* end point are the same, so this is useful when trying to reconcile
73
73
* nodes with source code.
74
74
*/
75
- def pathTo (span : Span , from : Positioned , skipZeroExtent : Boolean = false )(using Context ): List [Positioned ] = {
75
+ def pathTo (span : Span , from : List [ Positioned ] , skipZeroExtent : Boolean = false )(using Context ): List [Positioned ] = {
76
76
def childPath (it : Iterator [Any ], path : List [Positioned ]): List [Positioned ] = {
77
77
var bestFit : List [Positioned ] = path
78
78
while (it.hasNext) {
@@ -120,6 +120,6 @@ object NavigateAST {
120
120
case _ => path
121
121
}
122
122
}
123
- singlePath (from, Nil )
123
+ childPath (from.iterator , Nil )
124
124
}
125
125
}
Original file line number Diff line number Diff line change @@ -252,14 +252,14 @@ object Interactive {
252
252
* the tree closest enclosing `pos` and ends with an element of `trees`.
253
253
*/
254
254
def pathTo (trees : List [SourceTree ], pos : SourcePosition )(using Context ): List [Tree ] =
255
- trees.find(_.pos.contains(pos)) match {
256
- case Some (tree) => pathTo(tree.tree, pos.span)
257
- case None => Nil
258
- }
255
+ pathTo(trees.map(_.tree), pos.span)
259
256
260
257
def pathTo (tree : Tree , span : Span )(using Context ): List [Tree ] =
261
- if (tree.span.contains(span))
262
- NavigateAST .pathTo(span, tree, skipZeroExtent = true )
258
+ pathTo(List (tree), span)
259
+
260
+ private def pathTo (trees : List [Tree ], span : Span )(using Context ): List [Tree ] =
261
+ if (trees.exists(_.span.contains(span)))
262
+ NavigateAST .pathTo(span, trees, skipZeroExtent = true )
263
263
.collect { case t : untpd.Tree => t }
264
264
.dropWhile(! _.hasType).asInstanceOf [List [tpd.Tree ]]
265
265
else Nil
Original file line number Diff line number Diff line change @@ -222,4 +222,13 @@ class HoverTest {
222
222
| """ .withSource
223
223
.hover(m1 to m2, hoverContent(" example.SimpleEnum.Color" ))
224
224
}
225
+
226
+ @ Test def enums : Unit = {
227
+ code """ |package example
228
+ |enum TestEnum3:
229
+ | case ${m1}A ${m2} // no tooltip
230
+ |
231
+ | """ .withSource
232
+ .hover(m1 to m2, hoverContent(" example.TestEnum3" ))
233
+ }
225
234
}
You can’t perform that action at this time.
0 commit comments