Skip to content

Commit d26e8b6

Browse files
committed
Remove Documentation from Tasty Reflect
Nothing but the .raw field is set when we load documentation from Tasty. It doesn't make sense to expose Documentation as a separate data type.
1 parent e108e09 commit d26e8b6

File tree

5 files changed

+12
-58
lines changed

5 files changed

+12
-58
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,14 +2294,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
22942294
def pos: Option[Position] =
22952295
if self.exists then Some(self.sourcePos) else None
22962296

2297-
def documentation: Option[Documentation] =
2297+
def docstring: Option[String] =
22982298
import dotc.core.Comments.CommentsContext
22992299
val docCtx = ctx.docCtx.getOrElse {
23002300
throw new RuntimeException(
23012301
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
23022302
)
23032303
}
2304-
docCtx.docstring(self)
2304+
docCtx.docstring(self).map(_.raw)
23052305

23062306
def tree: Tree = FromSymbol.definitionFromSym(self)
23072307

@@ -2630,19 +2630,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26302630

26312631
end report
26322632

2633-
type Documentation = dotc.core.Comments.Comment
2634-
2635-
object Documentation extends DocumentationModule
2636-
2637-
given DocumentationMethods: DocumentationMethods with
2638-
extension (self: Documentation):
2639-
def raw: String = self.raw
2640-
def expanded: Option[String] = self.expanded
2641-
def usecases: List[(String, Option[DefDef])] =
2642-
self.usecases.map { uc => (uc.code, uc.tpdCode) }
2643-
end extension
2644-
end DocumentationMethods
2645-
26462633
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
26472634
if tree.isEmpty then None else Some(tree)
26482635

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
172172
*
173173
* +- Position
174174
*
175-
* +- Documentation
176-
*
177175
* +- Constant
178176
*
179177
* +- Symbol
@@ -3070,7 +3068,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
30703068
def pos: Option[Position]
30713069

30723070
/** The documentation for this symbol, if any */
3073-
def documentation: Option[Documentation]
3071+
def docstring: Option[String]
30743072

30753073
/** Tree of this definition
30763074
*
@@ -3733,36 +3731,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37333731
}
37343732

37353733

3736-
///////////////////
3737-
// DOCUMENTATION //
3738-
///////////////////
3739-
3740-
/** Attachment representing the documentation of a definition */
3741-
type Documentation <: AnyRef
3742-
3743-
/** Module object of `type Documentation` */
3744-
val Documentation: DocumentationModule
3745-
3746-
/** Methods of the module object `val Documentation` */
3747-
trait DocumentationModule { this: Documentation.type => }
3748-
3749-
/** Makes extension methods on `Documentation` available without any imports */
3750-
given DocumentationMethods: DocumentationMethods
3751-
3752-
/** Extension methods of `Documentation` */
3753-
trait DocumentationMethods {
3754-
extension (self: Documentation):
3755-
/** Raw documentation string */
3756-
def raw: String
3757-
3758-
/** Expanded documentation string, if any */
3759-
def expanded: Option[String]
3760-
3761-
/** List of usecases and their corresponding trees, if any */
3762-
def usecases: List[(String, Option[DefDef])]
3763-
3764-
end extension
3765-
}
37663734

37673735
///////////////
37683736
// UTILS //

scala3doc/src/dotty/dokka/tasty/BasicSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ trait BasicSupport:
3434

3535

3636
extension (sym: Symbol):
37-
def documentation = sym.documentation match
38-
case Some(comment) =>
39-
Map(ctx.sourceSet -> parseComment(comment, sym.tree))
37+
def documentation = sym.docstring match
38+
case Some(docstring) =>
39+
Map(ctx.sourceSet -> parseComment(docstring, sym.tree))
4040
case None =>
4141
Map.empty
4242

scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ trait ScaladocSupport { self: TastyParser =>
1212
import qctx.reflect._
1313

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

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

2525
comments.CommentExpander.cookComment(sym)(using ctx)
26-
.get.asInstanceOf[Documentation]
26+
.get.expanded.get
2727
else
28-
commentPre
28+
docstring
2929

30-
val commentString = commentNode.expanded getOrElse commentNode.raw
3130
val preparsed =
3231
comments.Preparser.preparse(comments.Cleaner.clean(commentString))
3332

tests/run-custom-args/tasty-inspector/tasty-documentation-inspector/Test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class DocumentationInspector extends TastyInspector {
2121

2222
override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match {
2323
case tree: Definition =>
24-
tree.symbol.documentation match {
25-
case Some(doc) => println(doc.raw)
24+
tree.symbol.docstring match {
25+
case Some(doc) => println(doc)
2626
case None => println()
2727
}
2828
super.traverseTree(tree)(owner)

0 commit comments

Comments
 (0)