Skip to content

Commit 8cd5c07

Browse files
KacperFKorbanpikinier20
authored andcommitted
Apply review changes
1 parent 994f076 commit 8cd5c07

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
@@ -252,44 +252,45 @@ class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using dc
252252
val nodes = root.getDescendants().asScala.collect {
253253
case fcb: mda.FencedCodeBlock => fcb
254254
}.toList
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.modify(_.each.messages.each.position.each.relativeLine).using(_ - 2)
277-
result.map { r =>
278-
r.copy(
279-
messages = r.messages.map { m =>
280-
m.copy(
281-
position = m.position.map { p =>
282-
p.copy(
283-
relativeLine = p.relativeLine - 2
284-
)
285-
}
286-
)
287-
}
288-
)
289-
}
255+
if nodes.nonEmpty then {
256+
val checkingFunc: SnippetChecker.SnippetCheckingFunc = snippetCheckingFunc(owner)
257+
nodes.foreach { node =>
258+
val snippet = node.getContentChars.toString
259+
val lineOffset = node.getStartLineNumber
260+
val info = node.getInfo.toString
261+
val argOverride =
262+
info.split(" ")
263+
.find(_.startsWith("sc:"))
264+
.map(_.stripPrefix("sc:"))
265+
.map(snippets.SCFlagsParser.parse)
266+
.flatMap(_.toOption)
267+
val snippetCompilationResult = checkingFunc(snippet, lineOffset, argOverride) match {
268+
case result@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+
result
276+
case result =>
277+
result.map { r =>
278+
r.copy(
279+
messages = r.messages.map { m =>
280+
m.copy(
281+
position = m.position.map { p =>
282+
p.copy(
283+
relativeLine = p.relativeLine - lineOffset
284+
)
285+
}
286+
)
287+
}
288+
)
289+
}
290+
}
291+
node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
292+
node.unlink()
290293
}
291-
node.insertBefore(new ExtendedFencedCodeBlock(node, snippetCompilationResult))
292-
node.unlink()
293294
}
294295
root
295296
}

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)