@@ -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 }
0 commit comments