@@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Flags.*
1010import dotty .tools .dotc .core .Names .Name
1111import dotty .tools .dotc .core .StdNames
1212import dotty .tools .dotc .core .Symbols .*
13- import dotty .tools .dotc .core .Types .Type
13+ import dotty .tools .dotc .core .Types .*
1414import dotty .tools .dotc .interactive .SourceTree
1515import dotty .tools .dotc .util .SourceFile
1616import dotty .tools .dotc .util .SourcePosition
@@ -109,14 +109,15 @@ object MetalsInteractive:
109109 * Returns the list of tuple enclosing symbol and
110110 * the symbol's expression type if possible.
111111 */
112+ @ tailrec
112113 def enclosingSymbolsWithExpressionType (
113114 path : List [Tree ],
114115 pos : SourcePosition ,
115116 indexed : IndexedContext ,
116117 skipCheckOnName : Boolean = false
117118 ): List [(Symbol , Type )] =
118119 import indexed .ctx
119- @ tailrec def go ( path : List [ Tree ]) : List [( Symbol , Type )] = path match
120+ path match
120121 // For a named arg, find the target `DefDef` and jump to the param
121122 case NamedArg (name, _) :: Apply (fn, _) :: _ =>
122123 val funSym = fn.symbol
@@ -204,8 +205,24 @@ object MetalsInteractive:
204205 Nil
205206
206207 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+ )
209226 else if head.symbol != NoSymbol then
210227 if skipCheckOnName ||
211228 MetalsInteractive .isOnName(
@@ -219,24 +236,21 @@ object MetalsInteractive:
219236 * https://github.com/lampepfl/dotty/issues/15937
220237 */
221238 else if head.isInstanceOf [TypeTree ] then
222- go (tail)
239+ enclosingSymbolsWithExpressionType (tail, pos, indexed )
223240 else Nil
224241 else
225242 val recovered = recoverError(head, indexed)
226243 if recovered.isEmpty then
227- go(tail)
244+ enclosingSymbolsWithExpressionType(
245+ tail,
246+ pos,
247+ indexed,
248+ skipCheckOnName
249+ )
228250 else recovered.map(sym => (sym, sym.info))
229251 end if
230252 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
240254 end enclosingSymbolsWithExpressionType
241255
242256 import dotty .tools .pc .utils .MtagsEnrichments .*
0 commit comments