Skip to content

Commit 5dc774e

Browse files
committed
move named tuples case lower
1 parent ea64296 commit 5dc774e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

Diff for: presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

+14-13
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,6 @@ object MetalsInteractive:
117117
): List[(Symbol, Type, Option[String])] =
118118
import indexed.ctx
119119
path match
120-
// Handle select on named tuples
121-
case (Apply(Apply(TypeApply(fun, List(t1, t2)), List(ddef)), List(Literal(Constant(i: Int))))) :: _
122-
if fun.symbol.exists && fun.symbol.name == nme.apply &&
123-
fun.symbol.owner.exists && fun.symbol.owner == getModuleIfDefined("scala.NamedTuple").moduleClass =>
124-
def getIndex(t: Tree): Option[Type] =
125-
t.tpe.dealias match
126-
case AppliedType(_, args) => args.get(i)
127-
case _ => None
128-
val name = getIndex(t1) match
129-
case Some(c: ConstantType) => c.value.stringValue
130-
case _ => ""
131-
val tpe = getIndex(t2).getOrElse(NoType)
132-
List((ddef.symbol, tpe, Some(name)))
133120
// For a named arg, find the target `DefDef` and jump to the param
134121
case NamedArg(name, _) :: Apply(fn, _) :: _ =>
135122
val funSym = fn.symbol
@@ -216,6 +203,20 @@ object MetalsInteractive:
216203
case _ =>
217204
Nil
218205

206+
// Handle select on named tuples
207+
case (Apply(Apply(TypeApply(fun, List(t1, t2)), List(ddef)), List(Literal(Constant(i: Int))))) :: _
208+
if fun.symbol.exists && fun.symbol.name == nme.apply &&
209+
fun.symbol.owner.exists && fun.symbol.owner == getModuleIfDefined("scala.NamedTuple").moduleClass =>
210+
def getIndex(t: Tree): Option[Type] =
211+
t.tpe.dealias match
212+
case AppliedType(_, args) => args.get(i)
213+
case _ => None
214+
val name = getIndex(t1) match
215+
case Some(c: ConstantType) => c.value.stringValue
216+
case _ => ""
217+
val tpe = getIndex(t2).getOrElse(NoType)
218+
List((ddef.symbol, tpe, Some(name)))
219+
219220
case path @ head :: tail =>
220221
if head.symbol.is(Exported) then
221222
val sym = head.symbol.sourceSymbol

0 commit comments

Comments
 (0)