Skip to content

Commit d4228a8

Browse files
committed
Refactor debug flag
1 parent 5f05011 commit d4228a8

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(
@@ -184,13 +183,15 @@ abstract class MarkupConversion[T](val repr: Repr, snippetChecker: SnippetChecke
184183
(str: String, lineOffset: SnippetChecker.LineOffset, argOverride: Option[SCFlags]) => {
185184
val arg = argOverride.fold(pathBasedArg)(pathBasedArg.overrideFlag(_))
186185

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

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

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

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

0 commit comments

Comments
 (0)