@@ -36,16 +36,20 @@ object HoverProvider:
36
36
val text = params.text().nn
37
37
val sourceFile = SourceFile .virtual(uri, text)
38
38
driver.run(uri, sourceFile)
39
+ val unit = driver.compilationUnits.get(uri)
39
40
40
- given ctx : Context = driver.currentCtx
41
+ given ctx : Context =
42
+ val ctx = driver.currentCtx
43
+ unit.map(ctx.fresh.setCompilationUnit).getOrElse(ctx)
41
44
val pos = driver.sourcePosition(params)
42
- val trees = driver.openedTrees(uri)
45
+ val path = unit
46
+ .map(unit => Interactive .pathTo(unit.tpdTree, pos.span))
47
+ .getOrElse(Interactive .pathTo(driver.openedTrees(uri), pos))
43
48
val indexedContext = IndexedContext (ctx)
44
49
45
50
def typeFromPath (path : List [Tree ]) =
46
51
if path.isEmpty then NoType else path.head.tpe
47
52
48
- val path = Interactive .pathTo(trees, pos)
49
53
val tp = typeFromPath(path)
50
54
val tpw = tp.widenTermRefExpr
51
55
// For expression we need to find all enclosing applies to get the exact generic type
@@ -72,7 +76,10 @@ object HoverProvider:
72
76
|path:
73
77
|- ${path.map(_.toString()).mkString(" \n - " )}
74
78
|trees:
75
- |- ${trees.map(_.toString()).mkString(" \n - " )}
79
+ |- ${unit
80
+ .map(u => List (u.tpdTree))
81
+ .getOrElse(driver.openedTrees(uri).map(_.tree))
82
+ .map(_.toString()).mkString(" \n - " )}
76
83
| """ .stripMargin,
77
84
s " $uri:: $posId"
78
85
)
@@ -83,15 +90,9 @@ object HoverProvider:
83
90
val skipCheckOnName =
84
91
! pos.isPoint // don't check isHoveringOnName for RangeHover
85
92
86
- val printerContext =
87
- driver.compilationUnits.get(uri) match
88
- case Some (unit) =>
89
- val newctx =
90
- ctx.fresh.setCompilationUnit(unit)
91
- Interactive .contextOfPath(enclosing)(using newctx)
92
- case None => ctx
93
+ val printerCtx = Interactive .contextOfPath(path)
93
94
val printer = ShortenedTypePrinter (search, IncludeDefaultParam .Include )(
94
- using IndexedContext (printerContext )
95
+ using IndexedContext (printerCtx )
95
96
)
96
97
MetalsInteractive .enclosingSymbolsWithExpressionType(
97
98
enclosing,
@@ -142,7 +143,8 @@ object HoverProvider:
142
143
expressionType = Some (expressionType),
143
144
symbolSignature = Some (hoverString),
144
145
docstring = Some (docString),
145
- forceExpressionType = forceExpressionType
146
+ forceExpressionType = forceExpressionType,
147
+ contextInfo = printer.getUsedRenamesInfo
146
148
)
147
149
).nn
148
150
case _ =>
@@ -176,6 +178,7 @@ object HoverProvider:
176
178
new ScalaHover (
177
179
expressionType = Some (tpeString),
178
180
symbolSignature = Some (s " $valOrDef $name$tpeString" ),
181
+ contextInfo = printer.getUsedRenamesInfo
179
182
)
180
183
)
181
184
case RefinedType (parent, _, _) =>
0 commit comments