Skip to content

Commit 95b3fb9

Browse files
committed
Dottydoc: Keep documentation on package objects
The documentation for packages must be set on the package object. When generating the docsite, dotty doc must then copy the documentation from the package object node to the package node, so that it is shown in the index for this package. In dotty doc, the comments are added to the "doc AST" in the `DocstringPhase`. Then, the doc for packages are copied from the matching package objects in the `PackageObjectsPhase`. This means that `PackageObjectsPhase` must be able to see the changes done by `DocstringPhase`, and therefor they cannot be in the same miniphase.
1 parent 91de029 commit 95b3fb9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class DocCompiler extends Compiler {
3030
List(new DocImplicitsPhase) ::
3131
List(new DocASTPhase) ::
3232
List(DocMiniTransformations(new UsecasePhase,
33-
new DocstringPhase,
34-
new PackageObjectsPhase,
33+
new DocstringPhase)) ::
34+
List(DocMiniTransformations(new PackageObjectsPhase,
3535
new LinkReturnTypes,
3636
new LinkParamListTypes,
3737
new LinkImplicitlyAddedTypes,

doc-tool/test/SimpleComments.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ class TestSimpleComments extends DottyDocTest {
2525
assertEquals(traitCmt, "<p>Hello, world!</p>")
2626
}
2727
}
28+
29+
@Test def commentOnPackageObject = {
30+
val source =
31+
"""
32+
|/** Hello, world! */
33+
|package object foobar { class A }
34+
""".stripMargin
35+
36+
checkSource(source) { packages =>
37+
val packageCmt = packages("foobar").comment.get.body
38+
assertEquals("<p>Hello, world!</p>", packageCmt)
39+
}
40+
}
2841
}

0 commit comments

Comments
 (0)