Skip to content

Commit eda984a

Browse files
authored
Merge pull request #15045 from dotty-staging/scaladoc/some-scaladoc-fixes
Fix expanding docstrings in Scaladoc
2 parents f110666 + 76157bc commit eda984a

File tree

4 files changed

+10
-453
lines changed

4 files changed

+10
-453
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait BasicSupport:
3737
Annotation(dri, params)
3838

3939
extension (using Quotes)(sym: reflect.Symbol)
40-
def documentation = sym.docstring.map(parseComment(_, sym.tree))
40+
def documentation = parseComment(sym.docstring.getOrElse(""), sym.tree)
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/ScalaDocSupport.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object ScaladocSupport:
2929

3030
defaultSyntax
3131
}
32-
case None =>
32+
case None =>
3333
pathBasedCommentSyntax()
3434
}
3535

@@ -41,17 +41,20 @@ object ScaladocSupport:
4141
}
4242
parser.parse(preparsed)
4343

44-
def parseComment(using Quotes, DocContext)(docstring: String, tree: reflect.Tree): Comment =
44+
def parseComment(using Quotes, DocContext)(docstring: String, tree: reflect.Tree): Option[Comment] =
4545
val commentString: String =
4646
if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
4747
import dotty.tools.dotc
48+
import dotty.tools.dotc.core.Comments.CommentsContext
4849
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
4950

51+
val docCtx = ctx.docCtx.get
52+
5053
val sym = tree.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
5154

52-
comments.CommentExpander.cookComment(sym)(using ctx)
53-
.get.expanded.get
55+
docCtx.templateExpander.expand(sym, sym.owner)
5456
else
5557
docstring
56-
57-
parseCommentString(commentString, tree.symbol, Some(tree.pos))
58+
if commentString == ""
59+
then None
60+
else Some(parseCommentString(commentString, tree.symbol, Some(tree.pos)))

0 commit comments

Comments
 (0)