Skip to content

Commit f740846

Browse files
kpbochenektgodzik
authored andcommitted
Always display types in worksheets
1 parent 6f37b75 commit f740846

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

mdoc/src/main/scala/mdoc/internal/worksheets/WorksheetProvider.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,15 @@ class WorksheetProvider(settings: Settings) {
131131
out
132132
.append(if (out.isEmpty) "" else ", ")
133133
.append(binder.name)
134-
.append("=")
134+
.append(": ")
135+
.append(binder.tpeString)
136+
.append(" = ")
135137
}
138+
if (isSingle)
139+
out
140+
.append(": ")
141+
.append(binder.tpeString)
142+
.append(" = ")
136143
val chunk = BlackWhite
137144
.tokenize(binder.value, width = margin - out.length)
138145
.map(_.getChars)

tests/worksheets/src/test/scala/tests/worksheets/WorksheetSuite.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class WorksheetSuite extends BaseSuite {
4242
|val x = 1.to(4).toVector
4343
|""".stripMargin,
4444
"""|
45-
|<val x = 1.to(4).toVector> // Vector(1, 2, 3, 4)
45+
|<val x = 1.to(4).toVector> // : Vector[Int] = Vect...
4646
|x: Vector[Int] = Vector(1, 2, 3, 4)
4747
|""".stripMargin
4848
)
@@ -54,7 +54,7 @@ class WorksheetSuite extends BaseSuite {
5454
|val y = 1.0
5555
|""".stripMargin,
5656
"""|lazy val x = 0.0
57-
|<val y = 1.0> // 1.0
57+
|<val y = 1.0> // : Double = 1.0
5858
|y: Double = 1.0
5959
|""".stripMargin
6060
)
@@ -65,7 +65,7 @@ class WorksheetSuite extends BaseSuite {
6565
|val List(x, y) = List(1, 2)
6666
|""".stripMargin,
6767
"""|
68-
|<val List(x, y) = List(1, 2)> // x=1, y=2
68+
|<val List(x, y) = List(1, 2)> // x: Int = 1, y: Int =...
6969
|x: Int = 1
7070
|y: Int = 2
7171
|""".stripMargin
@@ -77,7 +77,7 @@ class WorksheetSuite extends BaseSuite {
7777
|Stream.from(10)
7878
|""".stripMargin,
7979
"""|
80-
|<Stream.from(10)> // Stream(10,11,12,13,1...
80+
|<Stream.from(10)> // : Stream[Int] = Stre...
8181
|res0: Stream[Int] = Stream(
8282
| 10,
8383
| 11,
@@ -111,7 +111,7 @@ class WorksheetSuite extends BaseSuite {
111111
|<val x = {
112112
| println("hello")
113113
| 42
114-
|}> // 42
114+
|}> // : Int = 42
115115
|x: Int = 42
116116
|// hello
117117
|""".stripMargin
@@ -125,11 +125,11 @@ class WorksheetSuite extends BaseSuite {
125125
|val m = n * 10
126126
|""".stripMargin,
127127
"""|
128-
|<val n = 10> // 10
128+
|<val n = 10> // : Int = 10
129129
|n: Int = 10
130130
|<println(n)> // 10
131131
|// 10
132-
|<val m = n * 10> // 100
132+
|<val m = n * 10> // : Int = 100
133133
|m: Int = 100
134134
|""".stripMargin
135135
)
@@ -140,15 +140,15 @@ class WorksheetSuite extends BaseSuite {
140140
|val n = Future.successful(10)
141141
|""".stripMargin,
142142
"""|import scala.concurrent.Future
143-
|<val n = Future.successful(10)> // Future(Success(10))
143+
|<val n = Future.successful(10)> // : Future[Int] = Futu...
144144
|n: Future[Int] = Future(Success(10))
145145
|""".stripMargin
146146
)
147147

148148
// From 2.13 we get `name =` part
149149
val definitionCompat =
150150
"""|case class User(name: String)
151-
|<val n = User("Susan")> // User(name = "Susan")
151+
|<val n = User("Susan")> // : User = User(name =...
152152
|n: User = User(name = "Susan")
153153
|""".stripMargin
154154

@@ -158,7 +158,7 @@ class WorksheetSuite extends BaseSuite {
158158
|val n = User("Susan")
159159
|""".stripMargin,
160160
"""|case class User(name: String)
161-
|<val n = User("Susan")> // User("Susan")
161+
|<val n = User("Susan")> // : User = User("Susan...
162162
|n: User = User("Susan")
163163
|""".stripMargin,
164164
compat = Map(
@@ -224,7 +224,7 @@ class WorksheetSuite extends BaseSuite {
224224
|val y = "foobar".stripSuffix("bar")
225225
|""".stripMargin,
226226
"""|
227-
|<val x = "foobar".stripSuffix("bar")> // "foo"
227+
|<val x = "foobar".stripSuffix("bar")> // : String = "foo"
228228
|x: String = "foo"
229229
|""".stripMargin
230230
)
@@ -260,17 +260,17 @@ class WorksheetSuite extends BaseSuite {
260260
"""|case class Circle(x: Double, y: Double, radius: Double)
261261
|extension (c: Circle)
262262
| def circumference: Double = c.radius * math.Pi * 2
263-
|<val circle = Circle(0.0, 0.0, 2.0)> // Circle(x = 0.0,y = 0...
263+
|<val circle = Circle(0.0, 0.0, 2.0)> // : Circle = Circle(x ...
264264
|circle: Circle = Circle(
265265
| x = 0.0,
266266
| y = 0.0,
267267
| radius = 2.0
268268
|)
269-
|<circle.circumference> // 12.566370614359172
269+
|<circle.circumference> // : Double = 12.566370...
270270
|res0: Double = 12.566370614359172
271271
|extension [T](xs: List[T])
272272
| def second = xs.tail.head
273-
|<List(1,2,3).second> // 2
273+
|<List(1,2,3).second> // : Int = 2
274274
|res1: Int = 2
275275
|""".stripMargin
276276
)
@@ -285,7 +285,7 @@ class WorksheetSuite extends BaseSuite {
285285
"""|import $dep.`org.json4s:json4s-native_2.13:3.6.9`
286286
|import org.json4s._
287287
|import org.json4s.native.JsonMethods._
288-
|<parse("{ \"numbers\" : [1, 2, 3, 4] }")> // JObject(obj = List((...
288+
|<parse("{ \"numbers\" : [1, 2, 3, 4] }")> // : JValue = JObject(o...
289289
|res0: JValue = JObject(
290290
| obj = List(
291291
| (

0 commit comments

Comments
 (0)