Skip to content

Remove Documentation type from Reflect #10608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2316,14 +2316,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def pos: Option[Position] =
if self.exists then Some(self.sourcePos) else None

def documentation: Option[Documentation] =
def docstring: Option[String] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def docstring: Option[String] =
def docString: Option[String] =

import dotc.core.Comments.CommentsContext
val docCtx = ctx.docCtx.getOrElse {
throw new RuntimeException(
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
)
}
docCtx.docstring(self)
docCtx.docstring(self).map(_.raw)

def tree: Tree = FromSymbol.definitionFromSym(self)

Expand Down Expand Up @@ -2652,19 +2652,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

end report

type Documentation = dotc.core.Comments.Comment

object Documentation extends DocumentationModule

given DocumentationMethods: DocumentationMethods with
extension (self: Documentation):
def raw: String = self.raw
def expanded: Option[String] = self.expanded
def usecases: List[(String, Option[DefDef])] =
self.usecases.map { uc => (uc.code, uc.tpdCode) }
end extension
end DocumentationMethods

private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
if tree.isEmpty then None else Some(tree)

Expand Down
34 changes: 1 addition & 33 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
*
* +- SourceFile
*
* +- Documentation
*
* +- Constant
*
* +- Symbol
Expand Down Expand Up @@ -3089,7 +3087,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def pos: Option[Position]

/** The documentation for this symbol, if any */
def documentation: Option[Documentation]
def docstring: Option[String]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def docstring: Option[String]
def docString: Option[String]


/** Tree of this definition
*
Expand Down Expand Up @@ -3752,36 +3750,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
}


///////////////////
// DOCUMENTATION //
///////////////////

/** Attachment representing the documentation of a definition */
type Documentation <: AnyRef

/** Module object of `type Documentation` */
val Documentation: DocumentationModule

/** Methods of the module object `val Documentation` */
trait DocumentationModule { this: Documentation.type => }

/** Makes extension methods on `Documentation` available without any imports */
given DocumentationMethods: DocumentationMethods

/** Extension methods of `Documentation` */
trait DocumentationMethods {
extension (self: Documentation):
/** Raw documentation string */
def raw: String

/** Expanded documentation string, if any */
def expanded: Option[String]

/** List of usecases and their corresponding trees, if any */
def usecases: List[(String, Option[DefDef])]

end extension
}

///////////////
// UTILS //
Expand Down
6 changes: 3 additions & 3 deletions scala3doc/src/dotty/dokka/tasty/BasicSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ trait BasicSupport:


extension (sym: Symbol):
def documentation = sym.documentation match
case Some(comment) =>
Map(ctx.sourceSet -> parseComment(comment, sym.tree))
def documentation = sym.docstring match
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def documentation = sym.docstring match
def documentation = sym.docString match

case Some(docstring) =>
Map(ctx.sourceSet -> parseComment(docstring, sym.tree))
case None =>
Map.empty

Expand Down
9 changes: 4 additions & 5 deletions scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ trait ScaladocSupport { self: TastyParser =>
import qctx.reflect._

def parseComment(
commentPre: Documentation,
docstring: String,
tree: Tree
): dkkd.DocumentationNode = {
val commentNode =
val commentString: String =
if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
import dotty.tools.dotc
given ctx: dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx

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

comments.CommentExpander.cookComment(sym)(using ctx)
.get.asInstanceOf[Documentation]
.get.expanded.get
else
commentPre
docstring

val commentString = commentNode.expanded getOrElse commentNode.raw
val preparsed =
comments.Preparser.preparse(comments.Cleaner.clean(commentString))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class DocumentationInspector extends TastyInspector {

override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match {
case tree: Definition =>
tree.symbol.documentation match {
case Some(doc) => println(doc.raw)
tree.symbol.docstring match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tree.symbol.docstring match {
tree.symbol.docString match {

case Some(doc) => println(doc)
case None => println()
}
super.traverseTree(tree)(owner)
Expand Down