@@ -12,10 +12,7 @@ import dotty.dokka.tasty.comments.Comment
1212trait ScaladocSupport { self: TastyParser =>
1313 import qctx.reflect._
1414
15- def preparseComment(
16- docstring: String,
17- tree: Tree
18- ): Comment =
15+ def parseComment(docstring: String, tree: Tree): Comment =
1916 val commentString: String =
2017 if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
2118 import dotty.tools.dotc
@@ -50,92 +47,4 @@ trait ScaladocSupport { self: TastyParser =>
5047 comments.MarkdownCommentParser(comments.Repr(qctx)(tree.symbol))
5148 }
5249 parser.parse(preparsed)
53-
54- def parseComment(
55- docstring: String,
56- tree: Tree
57- ): dkkd.DocumentationNode = {
58- val commentString: String =
59- if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
60- import dotty.tools.dotc
61- given ctx: dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
62-
63- val sym = tree.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
64-
65- comments.CommentExpander.cookComment(sym)(using ctx)
66- .get.expanded.get
67- else
68- docstring
69-
70- val preparsed =
71- comments.Preparser.preparse(comments.Cleaner.clean(commentString))
72-
73- val commentSyntax =
74- preparsed.syntax.headOption match {
75- case Some(commentSetting) =>
76- CommentSyntax.parse(commentSetting).getOrElse {
77- val msg = s"not a valid comment syntax: $commentSetting, defaulting to Markdown syntax."
78- // we should update pos with span from documentation
79- report.warning(msg, tree.pos)
80- CommentSyntax.default
81- }
82- case None => ctx.args.defaultSyntax
83- }
84-
85- val parser = commentSyntax match {
86- case CommentSyntax.Wiki =>
87- comments.WikiCommentParser(comments.Repr(qctx)(tree.symbol))
88- case CommentSyntax.Markdown =>
89- comments.MarkdownCommentParser(comments.Repr(qctx)(tree.symbol))
90- }
91- val parsed = parser.parse(preparsed)
92-
93- import kotlin.collections.builders.{ListBuilder => KtListBuilder}
94- val bld = new KtListBuilder[dkkd.TagWrapper]
95- parsed.short match {
96- case Some(tag) => bld.add(dkkd.Description(tag))
97- case None => bld.add(dkkd.Description(dkk.text("")))
98- }
99- bld.add(dkkd.Description(parsed.body))
100-
101- inline def addOpt(opt: Option[dkkd.DocTag])(wrap: dkkd.DocTag => dkkd.TagWrapper) =
102- opt.foreach { t => bld.add(wrap(t)) }
103-
104- inline def addSeq[T](seq: Iterable[T])(wrap: T => dkkd.TagWrapper) =
105- seq.foreach { t => bld.add(wrap(t)) }
106-
107- // this is a total kludge, this should be done in a deeper layer but we'd
108- // need to refactor code there first
109- def correctParagraphTags(tag: dkkd.DocTag): dkkd.DocTag =
110- tag match {
111- case tag: dkkd.P =>
112- // NOTE we recurse once, since both the top-level element and its children can be P
113- // (there is no special root DocTag)
114- dkkd.Span(tag.getChildren.iterator.asScala.map(correctParagraphTags).toSeq.asJava, tag.getParams)
115- case tag => tag
116- }
117-
118- addSeq(parsed.authors)(dkkd.Author(_))
119- addOpt(parsed.version)(dkkd.Version(_))
120- addOpt(parsed.since)(dkkd.Since(_))
121- addOpt(parsed.deprecated)(dkkd.Deprecated(_))
122- addSeq(parsed.todo)(ScalaTagWrapper.Todo.apply)
123- addSeq(parsed.see)(ScalaTagWrapper.See.apply)
124- addSeq(parsed.note)(ScalaTagWrapper.Note.apply)
125- addSeq(parsed.example)(ScalaTagWrapper.Example.apply)
126-
127- addOpt(parsed.constructor)(dkkd.Constructor(_))
128- addSeq(parsed.valueParams){ case (name, tag) =>
129- ScalaTagWrapper.NestedNamedTag("Param", name, dkk.text(name), correctParagraphTags(tag))
130- }
131- addSeq(parsed.typeParams){ case (name, tag) =>
132- ScalaTagWrapper.NestedNamedTag("Type param", name, dkk.text(name), correctParagraphTags(tag))
133- }
134- addSeq(parsed.throws){ case (key, (exc, desc)) =>
135- ScalaTagWrapper.NestedNamedTag("Throws", key, exc, correctParagraphTags(desc))
136- }
137- addOpt(parsed.result)(dkkd.Return(_))
138-
139- new dkkd.DocumentationNode(bld.build())
140- }
14150}
0 commit comments