Skip to content
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 @@ -25,6 +25,8 @@ import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.InteractiveEnrichments.*
import dotty.tools.dotc.ast.untpd.InferredTypeTree
import dotty.tools.dotc.core.StdNames

object HoverProvider:

Expand Down Expand Up @@ -131,7 +133,12 @@ object HoverProvider:
.flatMap(symTpe => search.symbolDocumentation(symTpe._1, contentType))
.map(_.docstring())
.mkString("\n")
printer.expressionType(exprTpw) match

val expresionTypeOpt =
if symbol.name == StdNames.nme.??? then
InferExpectedType(search, driver, params).infer()
else printer.expressionType(exprTpw)
expresionTypeOpt match
case Some(expressionType) =>
val forceExpressionType =
!pos.span.isZeroExtent || (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dotty.tools.pc.tests.hover

import dotty.tools.pc.base.BaseHoverSuite

import org.junit.Test

class HoverHoleSuite extends BaseHoverSuite:
@Test def basic =
check(
"""object a {
| val x: Int = ?@@??
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|Int
|```
|**Symbol signature**:
|```scala
|def ???: Nothing
|```
|""".stripMargin
)

@Test def function =
check(
"""object a {
| def m(i: Int) = ???
| val x = m(??@@?)
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|Int
|```
|**Symbol signature**:
|```scala
|def ???: Nothing
|```
|""".stripMargin
)

@Test def constructor =
check(
"""object a {
| val x = List(1, ?@@??)
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|Int
|```
|**Symbol signature**:
|```scala
|def ???: Nothing
|```
|""".stripMargin
)

@Test def bounds =
check(
"""|trait Foo
|def foo[T <: Foo](a: T): Boolean = ???
|val _ = foo(?@@??)
|""".stripMargin,
"""|**Expression type**:
|```scala
|Foo
|```
|**Symbol signature**:
|```scala
|def ???: Nothing
|```
|""".stripMargin
)
Loading