Skip to content

Commit cf2fe54

Browse files
committed
UX improvements for scaladoc
1 parent e79ca04 commit cf2fe54

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

scaladoc-testcases/src/tests/listindocstring.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
package tests
2+
package listindocstring
3+
14
/**
25
* These are useful methods that exist for both $some and $none.
3-
* * [[isDefined]] — True if not empty
6+
* - [[isDefined]] — True if not empty
47
* - [[isEmpty]] — True if empty
58
* - [[nonEmpty]] — True if not empty
69
* - [[orElse]] — Evaluate and return alternate optional value if empty
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package tests
2+
package secondaryconstructors
3+
4+
class Person(val firstName: String, val lastName: String, val age: Int):
5+
def this(firstName: String) = this(firstName, "", 0)
6+
def this(firstName: String, lastName: String) = this(firstName, lastName, 0)
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tests
2+
package traitmethodsgrouping
3+
4+
trait Promise:
5+
def shouldBeAbstract: Int
6+
def shouldBeConcrete: Int = 1

scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ case class SourceLinks(links: Seq[SourceLink], projectRoot: Path):
122122
else resolveRelativePath(rawPath)
123123

124124
def pathTo(member: Member): Option[String] =
125-
member.sources.flatMap(s => pathTo(Paths.get(s.path), member.name, Option(s.lineNumber).map(_ + 1)))
125+
member.sources.flatMap(s => pathTo(s.path, member.name, Option(s.lineNumber).map(_ + 1)))
126126

127127
object SourceLinks:
128128

scaladoc/src/dotty/tools/scaladoc/api.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ case class Member(
146146
modifiers: Seq[Modifier] = Nil,
147147
annotations: List[Annotation] = Nil,
148148
signature: Signature = Signature(),
149-
sources: Option[TastyDocumentableSource] = None,
149+
sources: Option[TastyMemberSource] = None,
150150
origin: Origin = Origin.RegularlyDefined,
151151
inheritedFrom: Option[InheritedFrom] = None,
152152
graph: HierarchyGraph = HierarchyGraph.empty,
@@ -231,4 +231,4 @@ extension (s: Signature)
231231
case l: Link => l.name
232232
}.mkString
233233

234-
case class TastyDocumentableSource(val path: String, val lineNumber: Int)
234+
case class TastyMemberSource(val path: java.nio.file.Path, val lineNumber: Int)

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
6868

6969
def source(m: Member): Seq[AppliedTag] =
7070
summon[DocContext].sourceLinks.pathTo(m).fold(Nil){ link =>
71-
tableRow("Source", a(href := link)("(source)"))
71+
tableRow("Source", a(href := link)(m.sources.fold("(source)")(_.path.getFileName().toString())))
7272
}
7373

7474
def deprecation(m: Member): Seq[AppliedTag] = m.deprecated.fold(Nil){ a =>
@@ -202,22 +202,34 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
202202
case m: Member => m.inheritedFrom.nonEmpty
203203
case g: MGroup => g.members.exists(isInherited)
204204

205+
private def isAbstract(m: Member | MGroup): Boolean = m match
206+
case m: Member => m.modifiers.contains(Modifier.Abstract)
207+
case g: MGroup => g.members.exists(isAbstract)
208+
205209
private type SubGroup = (String, Seq[Member | MGroup])
206210
private def buildGroup(name: String, subgroups: Seq[SubGroup]): Tab =
207211
val all = subgroups.map { case (name, members) =>
208212
val (allInherited, allDefined) = members.partition(isInherited)
209213
val (depDefined, defined) = allDefined.partition(isDeprecated)
210214
val (depInherited, inherited) = allInherited.partition(isDeprecated)
211-
(
212-
actualGroup(name, defined),
213-
actualGroup(s"Deprecated ${name.toLowerCase}", depDefined),
214-
actualGroup(s"Inherited ${name.toLowerCase}", inherited),
215-
actualGroup(s"Deprecated and Inherited ${name.toLowerCase}", depInherited)
215+
val normalizedName = name.toLowerCase
216+
val definedWithGroup = if Set("methods", "fields").contains(normalizedName) then
217+
val (abstr, concr) = defined.partition(isAbstract)
218+
Seq(
219+
actualGroup(s"Abstract ${normalizedName}", abstr),
220+
actualGroup(s"Concrete ${normalizedName}", concr)
221+
)
222+
else
223+
Seq(actualGroup(name, defined))
224+
225+
definedWithGroup ++ List(
226+
actualGroup(s"Deprecated ${normalizedName}", depDefined),
227+
actualGroup(s"Inherited ${normalizedName}", inherited),
228+
actualGroup(s"Deprecated and Inherited ${normalizedName}", depInherited)
216229
)
217230
}
218231

219-
val children =
220-
all.flatMap(_._1) ++ all.flatMap(_._2) ++ all.flatMap(_._3) ++ all.flatMap(_._4)
232+
val children = all.flatten.flatten
221233
if children.isEmpty then emptyTab
222234
else Tab(name, name, h2(tabAttr(name))(name) +: children, "selected")
223235

scaladoc/src/dotty/tools/scaladoc/tasty/BasicSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ trait BasicSupport:
3636
def documentation = sym.docstring.map(parseComment(_, sym.tree))
3737

3838
def source(using Quotes) =
39-
val path = sym.pos.map(_.sourceFile.jpath).filter(_ != null).map(_.toAbsolutePath).map(_.toString)
40-
path.map(TastyDocumentableSource(_, sym.pos.get.startLine))
39+
val path = sym.pos.map(_.sourceFile.jpath).filter(_ != null).map(_.toAbsolutePath)
40+
path.map(TastyMemberSource(_, sym.pos.get.startLine))
4141

4242
def getAnnotations(): List[Annotation] =
4343
sym.annotations.filterNot(_.symbol.packageName.startsWith("scala.annotation.internal")).map(parseAnnotation).reverse

scaladoc/src/dotty/tools/scaladoc/tasty/comments/MarkdownParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object MarkdownParser {
3636
) ++ additionalExtensions
3737

3838
new MutableDataSet()
39-
.setFrom(ParserEmulationProfile.KRAMDOWN.getOptions)
39+
.setFrom(ParserEmulationProfile.COMMONMARK.getOptions)
4040
.set(Parser.EXTENSIONS, Arrays.asList(extArray:_*))
4141
.set(EmojiExtension.ROOT_IMAGE_PATH,
4242
"https://github.global.ssl.fastly.net/images/icons/emoji/")

0 commit comments

Comments
 (0)