Skip to content

Commit 93c1c08

Browse files
committed
Fix bugs with attributes display
1 parent 01f0c3e commit 93c1c08

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
3939

4040
def docAttributes(m: Member): Seq[AppliedTag] =
4141

42-
def nested(name: String, on: SortedMap[String, DocPart]): Seq[AppliedTag] =
43-
if on.isEmpty then Nil else
44-
tableRow(name, dl(cls := "attributes")(
45-
on.map { case (name, value) => tableRow(name, renderDocPart(value))}.toList:_*
46-
))
42+
def flattened(on: SortedMap[String, DocPart]): Seq[AppliedTag] =
43+
on.flatMap { case (name, value) => tableRow(name, renderDocPart(value))}.toSeq
4744

4845
def list(name: String, on: List[DocPart]): Seq[AppliedTag] =
4946
if on.isEmpty then Nil else tableRow(name, div(on.map(e => div(renderDocPart(e)))))
@@ -54,10 +51,10 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
5451
def authors(authors: List[DocPart]) = if summon[DocContext].args.includeAuthors then list("Authors:", authors) else Nil
5552

5653
m.docs.fold(Nil)(d =>
57-
nested("Type parameters:", d.typeParams) ++
58-
nested("Value parameters:", d.valueParams) ++
54+
flattened(d.typeParams) ++
55+
flattened(d.valueParams) ++
5956
opt("Returns:", d.result) ++
60-
nested("Throws:", d.throws) ++
57+
list("Throws:", d.throws) ++
6158
opt("Constructor:", d.constructor) ++
6259
authors(d.authors) ++
6360
list("See also:", d.see) ++

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.vladsch.flexmark.util.{ast => mdu, sequence}
88
import com.vladsch.flexmark.{ast => mda}
99
import com.vladsch.flexmark.formatter.Formatter
1010
import com.vladsch.flexmark.util.options.MutableDataSet
11+
import com.vladsch.flexmark.util.sequence.BasedSequence
1112

1213
import scala.quoted._
1314
import dotty.tools.scaladoc.tasty.comments.markdown.ExtendedFencedCodeBlock
@@ -25,7 +26,7 @@ case class Comment (
2526
authors: List[DocPart],
2627
see: List[DocPart],
2728
result: Option[DocPart],
28-
throws: SortedMap[String, DocPart],
29+
throws: List[DocPart],
2930
valueParams: SortedMap[String, DocPart],
3031
typeParams: SortedMap[String, DocPart],
3132
version: Option[DocPart],
@@ -145,6 +146,16 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) {
145146
}
146147
}
147148

149+
def linkedExceptions(exceptions: SortedMap[String, T]): List[DocPart] = {
150+
exceptions.map { (name, body) =>
151+
val link: DocLink = resolveLink(name)
152+
val merged = mergeLinkWithBody(link, body)
153+
markupToDokka(merged)
154+
}.toList
155+
}
156+
157+
def mergeLinkWithBody(link: DocLink, body: T): T
158+
148159
final def parse(preparsed: PreparsedComment): Comment =
149160
val markup = stringToMarkup(preparsed.body)
150161
val body = markupToDokkaCommentBody(processSnippets(markup, preparsed))
@@ -154,7 +165,7 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) {
154165
authors = filterEmpty(preparsed.authors).map(markupToDokka),
155166
see = filterEmpty(preparsed.see).map(markupToDokka),
156167
result = single("@result", preparsed.result).map(markupToDokka),
157-
throws = filterEmpty(preparsed.throws).view.mapValues(markupToDokka).to(SortedMap),
168+
throws = linkedExceptions(filterEmpty(preparsed.throws)),
158169
valueParams = filterEmpty(preparsed.valueParams).view.mapValues(markupToDokka).to(SortedMap),
159170
typeParams = filterEmpty(preparsed.typeParams).view.mapValues(markupToDokka).to(SortedMap),
160171
version = single("@version", preparsed.version).map(markupToDokka),
@@ -201,6 +212,18 @@ class MarkdownCommentParser(repr: Repr)(using dctx: DocContext)
201212

202213
def processSnippets(root: mdu.Node, preparsed: PreparsedComment): mdu.Node =
203214
FlexmarkSnippetProcessor.processSnippets(root, Some(preparsed), snippetCheckingFunc(owner))
215+
216+
def mergeLinkWithBody(link: DocLink, body: mdu.Node): mdu.Node = {
217+
import dotty.tools.scaladoc.tasty.comments.markdown._
218+
val str = link match
219+
case DocLink.ToURL(url) => url
220+
case DocLink.ToDRI(dri, name) => name
221+
case DocLink.UnresolvedDRI(query, msg) => query
222+
val sequence = BasedSequence.EmptyBasedSequence().append(str)
223+
val node = new DocLinkNode(link, "", sequence)
224+
body.prependChild(node)
225+
body
226+
}
204227
}
205228

206229
class WikiCommentParser(repr: Repr)(using DocContext)
@@ -259,3 +282,13 @@ class WikiCommentParser(repr: Repr)(using DocContext)
259282
def processSnippets(root: wiki.Body, preparsed: PreparsedComment): wiki.Body =
260283
// Currently not supported
261284
root
285+
286+
def mergeLinkWithBody(link: DocLink, body: wiki.Body): wiki.Body =
287+
val linkNode = wiki.Link(link, None)
288+
val newBody = body match {
289+
case wiki.Body(List(wiki.Paragraph(wiki.Chain(content)))) =>
290+
val descr = wiki.Text(" ") +: content
291+
wiki.Body(List(wiki.Paragraph(wiki.Chain(linkNode +: descr))))
292+
case _ => body
293+
}
294+
newBody

0 commit comments

Comments
 (0)