collectScreenshots: improve comment grabbing algorithm

Instead of taking the first block comment,
take the last block comment before fun main.

There was one case with a commented function
above main.
This commit is contained in:
Abe Pazos
2025-08-30 14:04:11 +02:00
parent e5f36fc1d1
commit 5b4a78bc89

View File

@@ -130,9 +130,10 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
val description = if (ktFile.isFile) { val description = if (ktFile.isFile) {
val codeLines = ktFile.readLines() val codeLines = ktFile.readLines()
val start = codeLines.indexOfFirst { it.startsWith("/**") }
val end = codeLines.indexOfFirst { it.endsWith("*/") }
val main = codeLines.indexOfFirst { it.startsWith("fun main") } val main = codeLines.indexOfFirst { it.startsWith("fun main") }
val head = codeLines.take(main)
val start = head.indexOfLast { it.startsWith("/**") }
val end = head.indexOfLast { it.endsWith("*/") }
if ((start < end) && (end < main)) { if ((start < end) && (end < main)) {
codeLines.subList(start + 1, end).joinToString("\n") { line -> codeLines.subList(start + 1, end).joinToString("\n") { line ->