Skip to content

Commit 0cbbd2f

Browse files
committed
Apply review changes
1 parent bdaea56 commit 0cbbd2f

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

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

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -251,44 +251,45 @@ class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using dc
251251
val nodes = root.getDescendants().asScala.collect {
252252
case fcb: mda.FencedCodeBlock => fcb
253253
}.toList
254-
val checkingFunc: SnippetChecker.SnippetCheckingFunc = snippetCheckingFunc(owner)
255-
nodes.foreach { node =>
256-
val snippet = node.getContentChars.toString
257-
val lineOffset = node.getStartLineNumber
258-
val info = node.getInfo.toString
259-
val argOverride =
260-
info.split(" ")
261-
.find(_.startsWith("sc:"))
262-
.map(_.stripPrefix("sc:"))
263-
.map(snippets.SCFlagsParser.parse)
264-
.flatMap(_.toOption)
265-
val snippetCompilationResult = checkingFunc(snippet, lineOffset, argOverride) match {
266-
case result@Some(SnippetCompilationResult(wrapped, _, _, _)) if dctx.snippetCompilerArgs.debug =>
267-
val s = sequence.BasedSequence.EmptyBasedSequence()
268-
.append(wrapped)
269-
.append(sequence.BasedSequence.EOL)
270-
val content = mdu.BlockContent()
271-
content.add(s, 0)
272-
node.setContent(content)
273-
result
274-
case result =>
275-
// result.modify(_.each.messages.each.position.each.relativeLine).using(_ - 2)
276-
result.map { r =>
277-
r.copy(
278-
messages = r.messages.map { m =>
279-
m.copy(
280-
position = m.position.map { p =>
281-
p.copy(
282-
relativeLine = p.relativeLine - 2
283-
)
284-
}
285-
)
286-
}
287-
)
288-
}
254+
if nodes.nonEmpty then {
255+
val checkingFunc: SnippetChecker.SnippetCheckingFunc = snippetCheckingFunc(owner)
256+
nodes.foreach { node =>
257+
val snippet = node.getContentChars.toString
258+
val lineOffset = node.getStartLineNumber
259+
val info = node.getInfo.toString
260+
val argOverride =
261+
info.split(" ")
262+
.find(_.startsWith("sc:"))
263+
.map(_.stripPrefix("sc:"))
264+
.map(snippets.SCFlagsParser.parse)
265+
.flatMap(_.toOption)
266+
val snippetCompilationResult = checkingFunc(snippet, lineOffset, argOverride) match {
267+
case result@Some(SnippetCompilationResult(wrapped, _, _, _)) if dctx.snippetCompilerArgs.debug =>
268+
val s = sequence.BasedSequence.EmptyBasedSequence()
269+
.append(wrapped)
270+
.append(sequence.BasedSequence.EOL)
271+
val content = mdu.BlockContent()
272+
content.add(s, 0)
273+
node.setContent(content)
274+
result
275+
case result =>
276+
result.map { r =>
277+
r.copy(
278+
messages = r.messages.map { m =>
279+
m.copy(
280+
position = m.position.map { p =>
281+
p.copy(
282+
relativeLine = p.relativeLine - lineOffset
283+
)
284+
}
285+
)
286+
}
287+
)
288+
}
289+
}
290+
node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
291+
node.unlink()
289292
}
290-
node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
291-
node.unlink()
292293
}
293294
root
294295
}

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import dotty.tools.scaladoc.snippets._
66

77
case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty):
88
def withClass(cls: String) = this.copy(classes = classes + cls)
9-
private def escapeQuotes(msg: String): String = msg.flatMap {
10-
case '"' => """
11-
case c => c.toString
12-
}
9+
private def escapeQuotes(msg: String): String = msg.replace("\"", """)
1310
def toHTML =
1411
val label = if messages.nonEmpty then s"""label="${messages.map(escapeQuotes).mkString("\n")}"""" else ""
1512
s"""<span id="$lineNo" class="${classes.mkString(" ")}" $label>$content</span>"""

0 commit comments

Comments
 (0)