Skip to content

Commit feb8b2e

Browse files
authored
Merge pull request #10608 from dotty-staging/scala3doc/tasty-reflect-hide-comments
Remove Documentation type from Reflect
2 parents af47a1c + eae6d18 commit feb8b2e

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
@@ -2316,14 +2316,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
23162316
def pos: Option[Position] =
23172317
if self.exists then Some(self.sourcePos) else None
23182318

2319-
def documentation: Option[Documentation] =
2319+
def docstring: Option[String] =
23202320
import dotc.core.Comments.CommentsContext
23212321
val docCtx = ctx.docCtx.getOrElse {
23222322
throw new RuntimeException(
23232323
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
23242324
)
23252325
}
2326-
docCtx.docstring(self)
2326+
docCtx.docstring(self).map(_.raw)
23272327

23282328
def tree: Tree = FromSymbol.definitionFromSym(self)
23292329

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

26532653
end report
26542654

2655-
type Documentation = dotc.core.Comments.Comment
2656-
2657-
object Documentation extends DocumentationModule
2658-
2659-
given DocumentationMethods: DocumentationMethods with
2660-
extension (self: Documentation):
2661-
def raw: String = self.raw
2662-
def expanded: Option[String] = self.expanded
2663-
def usecases: List[(String, Option[DefDef])] =
2664-
self.usecases.map { uc => (uc.code, uc.tpdCode) }
2665-
end extension
2666-
end DocumentationMethods
2667-
26682655
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
26692656
if tree.isEmpty then None else Some(tree)
26702657

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
192192
*
193193
* +- SourceFile
194194
*
195-
* +- Documentation
196-
*
197195
* +- Constant
198196
*
199197
* +- Symbol
@@ -3107,7 +3105,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
31073105
def pos: Option[Position]
31083106

31093107
/** The documentation for this symbol, if any */
3110-
def documentation: Option[Documentation]
3108+
def docstring: Option[String]
31113109

31123110
/** Tree of this definition
31133111
*
@@ -3770,36 +3768,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37703768
}
37713769

37723770

3773-
///////////////////
3774-
// DOCUMENTATION //
3775-
///////////////////
3776-
3777-
/** Attachment representing the documentation of a definition */
3778-
type Documentation <: AnyRef
3779-
3780-
/** Module object of `type Documentation` */
3781-
val Documentation: DocumentationModule
3782-
3783-
/** Methods of the module object `val Documentation` */
3784-
trait DocumentationModule { this: Documentation.type => }
3785-
3786-
/** Makes extension methods on `Documentation` available without any imports */
3787-
given DocumentationMethods: DocumentationMethods
3788-
3789-
/** Extension methods of `Documentation` */
3790-
trait DocumentationMethods {
3791-
extension (self: Documentation):
3792-
/** Raw documentation string */
3793-
def raw: String
3794-
3795-
/** Expanded documentation string, if any */
3796-
def expanded: Option[String]
3797-
3798-
/** List of usecases and their corresponding trees, if any */
3799-
def usecases: List[(String, Option[DefDef])]
3800-
3801-
end extension
3802-
}
38033771

38043772
///////////////
38053773
// 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)