@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Flags.*
10
10
import dotty .tools .dotc .core .Names .Name
11
11
import dotty .tools .dotc .core .StdNames
12
12
import dotty .tools .dotc .core .Symbols .*
13
- import dotty .tools .dotc .core .Types .Type
13
+ import dotty .tools .dotc .core .Types .*
14
14
import dotty .tools .dotc .interactive .SourceTree
15
15
import dotty .tools .dotc .util .SourceFile
16
16
import dotty .tools .dotc .util .SourcePosition
@@ -109,14 +109,15 @@ object MetalsInteractive:
109
109
* Returns the list of tuple enclosing symbol and
110
110
* the symbol's expression type if possible.
111
111
*/
112
+ @ tailrec
112
113
def enclosingSymbolsWithExpressionType (
113
114
path : List [Tree ],
114
115
pos : SourcePosition ,
115
116
indexed : IndexedContext ,
116
117
skipCheckOnName : Boolean = false
117
118
): List [(Symbol , Type )] =
118
119
import indexed .ctx
119
- @ tailrec def go ( path : List [ Tree ]) : List [( Symbol , Type )] = path match
120
+ path match
120
121
// For a named arg, find the target `DefDef` and jump to the param
121
122
case NamedArg (name, _) :: Apply (fn, _) :: _ =>
122
123
val funSym = fn.symbol
@@ -204,8 +205,24 @@ object MetalsInteractive:
204
205
Nil
205
206
206
207
case path @ head :: tail =>
207
- if head.symbol.is(Synthetic ) then
208
- go(tail)
208
+ if head.symbol.is(Exported ) then
209
+ head.symbol.info match
210
+ case TypeAlias (target : NamedType ) =>
211
+ val ss = target.symbol.sourceSymbol // exported type
212
+ List ((ss, ss.info))
213
+ case info => info.finalResultType match
214
+ case target : NamedType =>
215
+ val ss = target.symbol.sourceSymbol // exported term
216
+ List ((ss, ss.info))
217
+ case _ =>
218
+ enclosingSymbolsWithExpressionType(tail, pos, indexed, skipCheckOnName)
219
+ else if head.symbol.is(Synthetic ) then
220
+ enclosingSymbolsWithExpressionType(
221
+ tail,
222
+ pos,
223
+ indexed,
224
+ skipCheckOnName
225
+ )
209
226
else if head.symbol != NoSymbol then
210
227
if skipCheckOnName ||
211
228
MetalsInteractive .isOnName(
@@ -219,24 +236,21 @@ object MetalsInteractive:
219
236
* https://github.com/lampepfl/dotty/issues/15937
220
237
*/
221
238
else if head.isInstanceOf [TypeTree ] then
222
- go (tail)
239
+ enclosingSymbolsWithExpressionType (tail, pos, indexed )
223
240
else Nil
224
241
else
225
242
val recovered = recoverError(head, indexed)
226
243
if recovered.isEmpty then
227
- go(tail)
244
+ enclosingSymbolsWithExpressionType(
245
+ tail,
246
+ pos,
247
+ indexed,
248
+ skipCheckOnName
249
+ )
228
250
else recovered.map(sym => (sym, sym.info))
229
251
end if
230
252
case Nil => Nil
231
- end go
232
- go(path).map { (sym, tp) =>
233
- if sym.is(Synthetic ) && sym.name == StdNames .nme.apply then
234
- (sym, tp) // return synthetic apply, rather than the apply's owner
235
- else if sym.isClassConstructor && sym.isPrimaryConstructor then
236
- (sym, tp) // return the class constructor, rather than the class (so skip trait constructors)
237
- else
238
- (sym.sourceSymbol, tp)
239
- }
253
+ end match
240
254
end enclosingSymbolsWithExpressionType
241
255
242
256
import dotty .tools .pc .utils .MtagsEnrichments .*
0 commit comments