Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delias type members in hover #6366

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -293,8 +295,8 @@ class HoverProvider(
expressionType = Some(prettyType),
symbolSignature = Some(prettySignature),
docstring = Some(docstring),
forceExpressionType =
pos.start != pos.end || !prettySignature.endsWith(prettyType),
forceExpressionType = pos.start != pos.end || (!prettySignature
.endsWith(prettyType) && !symbol.isType),
range = if (range.isRange) Some(range.toLsp) else None,
contextInfo = history.getUsedRenamesInfo(),
contentType = contentType
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
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
)
)

}
Loading