Skip to content

Commit

Permalink
Merge pull request #15045 from dotty-staging/scaladoc/some-scaladoc-f…
Browse files Browse the repository at this point in the history
…ixes

Fix expanding docstrings in Scaladoc
  • Loading branch information
Kordyjan authored Apr 27, 2022
2 parents f110666 + 76157bc commit eda984a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 453 deletions.
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/BasicSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait BasicSupport:
Annotation(dri, params)

extension (using Quotes)(sym: reflect.Symbol)
def documentation = sym.docstring.map(parseComment(_, sym.tree))
def documentation = parseComment(sym.docstring.getOrElse(""), sym.tree)

def getAnnotations(): List[Annotation] =
sym.annotations.filterNot(_.symbol.packageName.startsWith("scala.annotation.internal")).map(parseAnnotation).reverse
Expand Down
15 changes: 9 additions & 6 deletions scaladoc/src/dotty/tools/scaladoc/tasty/ScalaDocSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object ScaladocSupport:

defaultSyntax
}
case None =>
case None =>
pathBasedCommentSyntax()
}

Expand All @@ -41,17 +41,20 @@ object ScaladocSupport:
}
parser.parse(preparsed)

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

val docCtx = ctx.docCtx.get

val sym = tree.symbol.asInstanceOf[dotc.core.Symbols.Symbol]

comments.CommentExpander.cookComment(sym)(using ctx)
.get.expanded.get
docCtx.templateExpander.expand(sym, sym.owner)
else
docstring

parseCommentString(commentString, tree.symbol, Some(tree.pos))
if commentString == ""
then None
else Some(parseCommentString(commentString, tree.symbol, Some(tree.pos)))
Loading

0 comments on commit eda984a

Please # to comment.