Skip to content

Commit

Permalink
Definition type on lhs hover
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Aug 21, 2021
1 parent dff09c0 commit e6eb5c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ class HoverProvider(val compiler: MetalsGlobal, params: OffsetParams) {
val tree = typedHoverTreeAt(pos)
(pos, tree)
}
println(tree.summaryString)
pprint.log(tree)
println(s"tree: ${tree.tpe}")
tree match {
case i @ Import(_, _) =>
for {
member <- i.selector(pos)
hover <- toHover(member, pos)
} yield hover
case _: Select | _: Apply | _: TypeApply | _: Ident =>
println(tree.tpe)
println("Parents:")
lastVisitedParentTrees.foreach { tree =>
println(tree)
println(tree.tpe)
}
val expanded = expandRangeToEnclosingApply(pos)
if (
expanded != null &&
Expand Down Expand Up @@ -87,7 +82,7 @@ class HoverProvider(val compiler: MetalsGlobal, params: OffsetParams) {
)
// Def, val or val definition, example `val x: Int = 1`
// Matches only if the cursor is over the definition name.
case v: ValOrDefDef if v.namePos.includes(pos) && v.symbol != null =>
case v: ValOrDefDef if (v.namePos.includes(pos) || pos.includes(v.namePos)) && v.symbol != null =>
val symbol = (v.symbol.getter: Symbol) match {
case NoSymbol => v.symbol
case getter => getter
Expand Down
29 changes: 27 additions & 2 deletions tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class HoverNamedArgSuite extends BaseHoverSuite {
)

check(
"range-longer-expression",
"range-longer-expression-1",
"""|package helpers
|
|class XDClass {
Expand Down Expand Up @@ -169,7 +169,7 @@ class HoverNamedArgSuite extends BaseHoverSuite {
)

check(
"range-longer-expression",
"range-expression-in-closure",
"""|package helpers
|
|class XDClass {
Expand Down Expand Up @@ -197,4 +197,29 @@ class HoverNamedArgSuite extends BaseHoverSuite {
"3.0" -> "def apply[A](elems: A*): Int".hover
)
)

check(
"range-lfs-of-valdef",
"""|package helpers
|
|class XDClass {
| def xd: Int = {
| <<val %<%l%>% = List(1,2,3)>>
| l.map { x =>
| x.to(x*x)
| .flatMap { y =>
| List(y + 2137)
| }
| .sum
| }.sum
| }
|}
|""".stripMargin,
"""```scala
|val l: List[Int]
|```""".stripMargin.hover,
compat = Map(
"3.0" -> "".hover
)
)
}

0 comments on commit e6eb5c9

Please sign in to comment.