Skip to content

Commit 5228da3

Browse files
committed
Refactor debug flag
1 parent c037996 commit 5228da3

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ class SnippetChecker()(using ctx: DocContext):
3434

3535
object SnippetChecker:
3636
type LineOffset = Int
37-
type SnippetCheckingFunc = (String, LineOffset, Option[SCFlags]) => Unit
37+
type SnippetCheckingFunc = (String, LineOffset, Option[SCFlags]) => Option[SnippetCompilationResult]

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetCompilationResult.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ case class Position(line: Int, column: Int, sourceLine: String)
88
case class SnippetCompilerMessage(position: Option[Position], message: String, level: MessageLevel)
99

1010
case class SnippetCompilationResult(
11+
wrappedSnippet: String,
1112
isSuccessful: Boolean,
1213
result: Option[AbstractFile],
1314
messages: Seq[SnippetCompilerMessage]

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetCompiler.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ class SnippetCompiler(
6161
}
6262

6363
private def additionalMessages(wrappedSnippet: WrappedSnippet, arg: SnippetCompilerArg, context: Context): Seq[SnippetCompilerMessage] = {
64-
(
6564
Option.when(arg.flag == SCFlags.Fail && !context.reporter.hasErrors)(
6665
SnippetCompilerMessage(None, "Snippet should not compile but compiled succesfully", MessageLevel.Error)
67-
) ++
68-
Option.when(arg.debug && !isSuccessful(arg, context))(
69-
SnippetCompilerMessage(None, s"\n${wrappedSnippet.snippet}", MessageLevel.Debug)
70-
)
71-
).toList
66+
).toList
7267
}
7368

7469
private def isSuccessful(arg: SnippetCompilerArg, context: Context): Boolean = {
@@ -94,5 +89,5 @@ class SnippetCompiler(
9489
additionalMessages(wrappedSnippet, arg, context)
9590

9691
val t = Option.when(!context.reporter.hasErrors)(target)
97-
SnippetCompilationResult(isSuccessful(arg, context), t, messages)
92+
SnippetCompilationResult(wrappedSnippet.snippet, isSuccessful(arg, context), t, messages)
9893
}

scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package tasty.comments
44
import scala.collection.immutable.SortedMap
55
import scala.util.Try
66

7-
import com.vladsch.flexmark.util.{ast => mdu}
7+
import com.vladsch.flexmark.util.{ast => mdu, sequence}
88
import com.vladsch.flexmark.{ast => mda}
99
import com.vladsch.flexmark.formatter.Formatter
1010
import com.vladsch.flexmark.util.options.MutableDataSet
@@ -40,8 +40,7 @@ case class Comment (
4040
groupNames: SortedMap[String, DocPart],
4141
groupPrio: SortedMap[String, Int],
4242
/** List of conversions to hide - containing e.g: `scala.Predef.FloatArrayOps` */
43-
hideImplicitConversions: List[DocPart],
44-
snippetCompilerData: SnippetCompilerData
43+
hideImplicitConversions: List[DocPart]
4544
)
4645

4746
case class PreparsedComment(
@@ -183,13 +182,15 @@ abstract class MarkupConversion[T](val repr: Repr, snippetChecker: SnippetChecke
183182
(str: String, lineOffset: SnippetChecker.LineOffset, argOverride: Option[SCFlags]) => {
184183
val arg = argOverride.fold(pathBasedArg)(pathBasedArg.overrideFlag(_))
185184

185+
val res = snippetChecker.checkSnippet(str, Some(data), arg, lineOffset)
186186
snippetChecker.checkSnippet(str, Some(data), arg, lineOffset).foreach { _ match {
187187
case r: SnippetCompilationResult if !r.isSuccessful =>
188188
val msg = s"In member ${s.name} (${s.dri.location}):\n${r.getSummary}"
189189
report.error(msg)(using dctx.compilerContext)
190190
case _ =>
191191
}
192192
}
193+
res
193194
}
194195
}
195196

@@ -216,12 +217,11 @@ abstract class MarkupConversion[T](val repr: Repr, snippetChecker: SnippetChecke
216217
groupDesc = filterEmpty(preparsed.groupDesc).view.mapValues(markupToDokka).to(SortedMap),
217218
groupNames = filterEmpty(preparsed.groupNames).view.mapValues(markupToDokka).to(SortedMap),
218219
groupPrio = preparsed.groupPrio,
219-
hideImplicitConversions = filterEmpty(preparsed.hideImplicitConversions).map(markupToDokka),
220-
snippetCompilerData = getSnippetCompilerData(owner)
220+
hideImplicitConversions = filterEmpty(preparsed.hideImplicitConversions).map(markupToDokka)
221221
)
222222
}
223223

224-
class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using DocContext)
224+
class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using dctx: DocContext)
225225
extends MarkupConversion[mdu.Node](repr, snippetChecker) {
226226

227227
def stringToMarkup(str: String) =
@@ -264,7 +264,16 @@ class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using Do
264264
.map(_.stripPrefix("sc:"))
265265
.map(snippets.SCFlagsParser.parse)
266266
.flatMap(_.toOption)
267-
checkingFunc(snippet, lineOffset, argOverride)
267+
checkingFunc(snippet, lineOffset, argOverride) match {
268+
case Some(SnippetCompilationResult(wrapped, _, _, _)) if dctx.snippetCompilerArgs.debug =>
269+
val s = sequence.BasedSequence.EmptyBasedSequence()
270+
.append(wrapped)
271+
.append(sequence.BasedSequence.EOL)
272+
val content = mdu.BlockContent()
273+
content.add(s, 0)
274+
node.setContent(content)
275+
case _ =>
276+
}
268277
}
269278
}
270279
root

0 commit comments

Comments
 (0)