Skip to content

Commit

Permalink
Always display Expression Type on hovers
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Aug 21, 2021
1 parent e6eb5c9 commit c457790
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 121 deletions.
15 changes: 6 additions & 9 deletions mtags/src/main/scala/scala/meta/internal/pc/HoverMarkup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ object HoverMarkup {
docstring: String
): String = {
val markdown = new StringBuilder()
val needsExpressionType = !symbolSignature.endsWith(expressionType)
if (needsExpressionType) {
markdown
.append("**Expression type**:\n")
.append("```scala\n")
.append(expressionType)
.append("\n```\n")
}
markdown
.append("**Expression type**:\n")
.append("```scala\n")
.append(expressionType)
.append("\n```\n")
if (symbolSignature.nonEmpty) {
markdown
.append(if (needsExpressionType) "**Symbol signature**:\n" else "")
.append("**Symbol signature**:\n")
.append("```scala\n")
.append(symbolSignature)
.append("\n```")
Expand Down
51 changes: 26 additions & 25 deletions tests/cross/src/test/scala/tests/hover/HoverDefnSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<val @@x = List(1)>>
|}
|""".stripMargin,
"""|val x: List[Int]
"""|List[Int]
|val x: List[Int]
|""".stripMargin.hover
)

Expand All @@ -20,7 +21,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<var @@x = List(1)>>
|}
|""".stripMargin,
"""|var x: List[Int]
"""|List[Int]
|var x: List[Int]
|""".stripMargin.hover
)

Expand All @@ -30,7 +32,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<def @@x = List(1)>>
|}
|""".stripMargin,
"""|def x: List[Int]
"""|List[Int]
|def x: List[Int]
|""".stripMargin.hover
)

Expand All @@ -40,7 +43,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<def @@method(x: Int) = List(x)>>
|}
|""".stripMargin,
"""|def method(x: Int): List[Int]
"""|List[Int]
|def method(x: Int): List[Int]
|""".stripMargin.hover
)

Expand All @@ -50,7 +54,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<def @@empty[T] = Option.empty[T]>>
|}
|""".stripMargin,
"""|def empty[T]: Option[T]
"""|Option[T]
|def empty[T]: Option[T]
|""".stripMargin.hover
)

Expand All @@ -72,10 +77,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| List(1).map(<<@@x>> => )
|}
|""".stripMargin,
"""|```scala
"""|Int
|x: Int
|```
|""".stripMargin
|""".stripMargin.hover
)

check(
Expand All @@ -84,10 +88,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| def method(<<@@x: Int>>): Int = x
|}
|""".stripMargin,
"""|```scala
"""|Int
|x: Int
|```
|""".stripMargin
|""".stripMargin.hover
)

check(
Expand All @@ -96,10 +99,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| <<def t@@his(x: Int) = this()>>
|}
|""".stripMargin,
"""|```scala
"""|a
|def this(x: Int): a
|```
|""".stripMargin,
|""".stripMargin.hover,
compat = Map(
"3.0" -> "def <init>(x: Int): a".hover
)
Expand All @@ -111,10 +113,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| def this(<<@@x: Int>>) = this()
|}
|""".stripMargin,
"""|```scala
"""|Int
|x: Int
|```
|""".stripMargin
|""".stripMargin.hover
)

check(
Expand All @@ -123,10 +124,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| def method(implicit <<@@x: Int>>) = this()
|}
|""".stripMargin,
"""|```scala
"""|Int
|implicit x: Int
|```
|""".stripMargin
|""".stripMargin.hover
)

check(
Expand All @@ -135,10 +135,9 @@ class HoverDefnSuite extends BaseHoverSuite {
| def method(implicit y: Int, <<@@x: Int>>) = this()
|}
|""".stripMargin,
"""|```scala
"""|Int
|implicit x: Int
|```
|""".stripMargin
|""".stripMargin.hover
)

check(
Expand Down Expand Up @@ -196,7 +195,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"head: Int".hover,
"""|Int
|head: Int""".stripMargin.hover,
compat = Map(
"3.0" -> "val head: Int".hover
)
Expand All @@ -211,7 +211,8 @@ class HoverDefnSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"value: Int".hover,
"""|Int
|value: Int""".stripMargin.hover,
compat = Map(
"3.0" -> "val value: Int".hover
)
Expand Down
74 changes: 74 additions & 0 deletions tests/cross/src/test/scala/tests/hover/HoverLiteralSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tests.hover

import tests.pc.BaseHoverSuite

class HoverLiteralSuite extends BaseHoverSuite {

check(
"literal-int",
"""object a {
| val x = 4@@2
|}
|""".stripMargin,
"""|```scala
|Int
|```""".stripMargin.hover
)

check(
"literal-double",
"""object a {
| val x = 4@@2d
|}
|""".stripMargin,
"""|```scala
|Double
|```""".stripMargin.hover
)

check(
"literal-float",
"""object a {
| val x = 4@@2f
|}
|""".stripMargin,
"""|```scala
|Float
|```""".stripMargin.hover
)

check(
"literal-long",
"""object a {
| val x = 4@@2L
|}
|""".stripMargin,
"""|```scala
|Long
|```""".stripMargin.hover
)

check(
"literal-string",
"""object a {
| val x = "Hel@@lo"
|}
|""".stripMargin,
"""|```scala
|String
|```""".stripMargin.hover
)

check(
"interpolator-part",
"""object a {
| val name = "John"
| s"Hel@@lo $name"
|}
|""".stripMargin,
"""|```scala
|String
|```""".stripMargin
)

}
45 changes: 21 additions & 24 deletions tests/cross/src/test/scala/tests/hover/HoverNamedArgSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| <<foo(nam@@ed = 2)>>
|}
|""".stripMargin,
"""|```scala
"""|**Expression type**:
|```scala
|Unit
|```
|**Symbol signature**:
|```scala
|def foo(named: Int): Unit
|```
|Runs foo
Expand Down Expand Up @@ -62,7 +67,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| println(<<new User(age = 42, n@@ame = "")>>)
|}
|""".stripMargin,
"def this(name: String, age: Int): User".hover,
"""|User
|def this(name: String, age: Int): User""".stripMargin.hover,
compat = Map(
"3.0" -> "name: String".hover
)
Expand All @@ -85,7 +91,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"def sum[B >: Int](implicit num: Numeric[B]): B".hover,
"""|B
|def sum[B >: Int](implicit num: Numeric[B]): B""".stripMargin.hover,
compat = Map(
"3.0" -> "def sum[B >: A](implicit num: Numeric[B]): B".hover
)
Expand All @@ -108,7 +115,9 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"Int".hover,
"""|```scala
|Int
|```""".stripMargin,
compat = Map(
"3.0" -> "def +(x: Int): Int".hover
)
Expand All @@ -132,7 +141,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"def sum[B >: Int](implicit num: Numeric[B]): B".hover,
"""|B
|def sum[B >: Int](implicit num: Numeric[B]): B""".stripMargin.hover,
compat = Map(
"3.0" -> "val l: List[Int]".hover
)
Expand All @@ -155,14 +165,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|immutable.IndexedSeq[Int]
|```
|**Symbol signature**:
|```scala
|def flatMap[B, That](f: Int => GenTraversableOnce[B])(implicit bf: CanBuildFrom[immutable.IndexedSeq[Int],B,That]): That
|```""".stripMargin.hover,
"""|immutable.IndexedSeq[Int]
|def flatMap[B, That](f: Int => GenTraversableOnce[B])(implicit bf: CanBuildFrom[immutable.IndexedSeq[Int],B,That]): That""".stripMargin.hover,
compat = Map(
"3.0" -> "x: Int".hover
)
Expand All @@ -185,14 +189,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"""|**Expression type**:
|```scala
|List[Int]
|```
|**Symbol signature**:
|```scala
|override def apply[A](xs: A*): List[A]
|```""".stripMargin.hover,
"""|List[Int]
|override def apply[A](xs: A*): List[A]""".stripMargin.hover,
compat = Map(
"3.0" -> "def apply[A](elems: A*): Int".hover
)
Expand All @@ -215,9 +213,8 @@ class HoverNamedArgSuite extends BaseHoverSuite {
| }
|}
|""".stripMargin,
"""```scala
|val l: List[Int]
|```""".stripMargin.hover,
"""|List[Int]
|val l: List[Int]""".stripMargin.hover,
compat = Map(
"3.0" -> "".hover
)
Expand Down
Loading

0 comments on commit c457790

Please sign in to comment.