@@ -251,44 +251,45 @@ class MarkdownCommentParser(repr: Repr, snippetChecker: SnippetChecker)(using dc
251
251
val nodes = root.getDescendants().asScala.collect {
252
252
case fcb : mda.FencedCodeBlock => fcb
253
253
}.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()
289
292
}
290
- node.insertBefore(new ExtendedFencedCodeBlock (node, snippetCompilationResult))
291
- node.unlink()
292
293
}
293
294
root
294
295
}
0 commit comments