From e6eb5c908f2d675ad3ace89b8d53cc8bb97336fd Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Sat, 21 Aug 2021 15:55:55 +0200 Subject: [PATCH] Definition type on lhs hover --- .../meta/internal/pc/HoverProvider.scala | 11 ++----- .../tests/hover/HoverNamedArgSuite.scala | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala index a40f8e2b2b6..c523d0f8716 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala @@ -36,7 +36,8 @@ 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 { @@ -44,12 +45,6 @@ class HoverProvider(val compiler: MetalsGlobal, params: OffsetParams) { 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 && @@ -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 diff --git a/tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala b/tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala index b42dc4a496b..b4da5383372 100644 --- a/tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala +++ b/tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala @@ -139,7 +139,7 @@ class HoverNamedArgSuite extends BaseHoverSuite { ) check( - "range-longer-expression", + "range-longer-expression-1", """|package helpers | |class XDClass { @@ -169,7 +169,7 @@ class HoverNamedArgSuite extends BaseHoverSuite { ) check( - "range-longer-expression", + "range-expression-in-closure", """|package helpers | |class XDClass { @@ -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 = { + | <% = 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 + ) + ) }