Skip to content

Commit

Permalink
fix: delias type members in hover
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Apr 30, 2024
1 parent edbe6c3 commit f31ad61
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ class HoverProvider(
lookupSymbol = name => context.lookupSymbol(name, _ => true) :: Nil,
renames = re
)
val prettyType = metalsToLongString(tpe.widen.finalResultType, history)
val prettyType =
metalsToLongString(tpe.widen.finalResultType.map(_.dealias), history)
val lspRange = if (range.isRange) Some(range.toLsp) else None
Some(
new ScalaHover(
Expand Down Expand Up @@ -282,7 +283,8 @@ class HoverProvider(
val flags = List(symbolFlagString(symbol), keyword, name)
.filterNot(_.isEmpty)
.mkString(" ")
val prettyType = metalsToLongString(tpe.widen.finalResultType, history)
val prettyType =
metalsToLongString(tpe.widen.finalResultType.map(_.dealias), history)
val macroSuffix =
if (symbol.isMacro) " = macro"
else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.StdNames.*
import dotty.tools.dotc.core.SymDenotations.NoDenotation
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.AliasingBounds
import dotty.tools.dotc.core.Types.AppliedType
import dotty.tools.dotc.core.Types.RefinedType
import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.Types.TypeBounds
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
Expand Down Expand Up @@ -375,8 +378,13 @@ object MtagsEnrichments extends ScalametaCommonEnrichments:
def metalsDealias(using Context): Type =
tpe.dealias match
case app @ AppliedType(tycon, params) =>
// we dealias applied type params by hand, because `dealias` doesn't do it
AppliedType(tycon, params.map(_.metalsDealias))
case aliasingBounds: AliasingBounds =>
aliasingBounds.derivedAlias(aliasingBounds.alias.dealias)
case TypeBounds(lo, hi) =>
TypeBounds(lo.dealias, hi.dealias)
case RefinedType(parent, name, refinedInfo) =>
RefinedType(parent.dealias, name, refinedInfo.metalsDealias)
case dealised => dealised

end MtagsEnrichments
10 changes: 9 additions & 1 deletion tests/cross/src/test/scala/tests/hover/HoverDefnSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ class HoverDefnSuite extends BaseHoverSuite {
"""|object a {
| type <<M@@yType>> = Int
|}""".stripMargin,
"type MyType: MyType".hover
"""|**Expression type**:
|```scala
|Int
|```
|**Symbol signature**:
|```scala
|type MyType: MyType
|```
|""".stripMargin
)

check(
Expand Down
55 changes: 55 additions & 0 deletions tests/cross/src/test/scala/tests/hover/HoverTermSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,59 @@ class HoverTermSuite extends BaseHoverSuite {
|""".stripMargin,
"".stripMargin
)

check(
"dealias type members in val definition",
"""object Obj {
| trait A extends Sup { self =>
| type T
| def member : T
| }
| val x: A { type T = Int} = ???
|
| <<x.mem@@ber>>
|
|}""".stripMargin,
"""def member: Int""".stripMargin.hover
)

check(
"dealias-type-members-in-argument-of-anonymous-function",
"""object Obj {
| trait A extends Sup { self =>
| type T
| def fun(
| body: A { type T = self.T} => Unit
| ) =
| ()
| }
| val x: A { type T = Int} = ???
|
| x.fun { <<y@@y>> =>
| ()
| }
|
|}""".stripMargin,
"""|**Expression type**:
|```scala
|A{type T = Int}
|```
|**Symbol signature**:
|```scala
|yy: A{type T = dealias-type-members-in-argument-of-anonymous-function.Obj.x.T}
|```
|""".stripMargin,
compat = Map(
"3" -> """|**Expression type**:
|```scala
|A{type T = Int}
|```
|**Symbol signature**:
|```scala
|yy: A{type T = x.T}
|```
|""".stripMargin
)
)

}

0 comments on commit f31ad61

Please sign in to comment.