Skip to content

Commit f95b67f

Browse files
committed
feat: Improve function filtering logic and enhance table row parsing regex
1 parent 1c8cba1 commit f95b67f

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

mpp-core/src/commonMain/kotlin/cc/unitmesh/devins/document/docql/CodeDocQLExecutor.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,14 @@ class CodeDocQLExecutor(
377377
// Filter to function-level chunks and require EXACT name match
378378
val exactMatches = chunks.filter { chunk ->
379379
val title = chunk.chapterTitle ?: ""
380-
// Must be a function (not a class)
381-
val isFunction = title.contains("fun ") ||
382-
(!title.startsWith("class ") &&
383-
!title.startsWith("interface ") &&
384-
!title.startsWith("enum ") &&
385-
!title.startsWith("object ") &&
386-
title.contains("("))
387-
388-
if (!isFunction) return@filter false
389-
380+
// Must NOT be a class/interface/enum/object (i.e., must be a function)
381+
val isClassLike = title.startsWith("class ") ||
382+
title.startsWith("interface ") ||
383+
title.startsWith("enum ") ||
384+
title.startsWith("object ")
385+
386+
if (isClassLike) return@filter false
387+
390388
val funcName = extractFunctionNameFromTitle(title)
391389
funcName.equals(functionName, ignoreCase = true)
392390
}

mpp-core/src/commonMain/kotlin/cc/unitmesh/devins/document/docql/MarkdownDocQLExecutor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ class MarkdownDocQLExecutor(
477477
val headers = parseTableRow(tableLines[0])
478478

479479
// Skip separator line (e.g., |---|---|)
480-
val dataRows = if (tableLines.size > 2 && tableLines[1].trim().matches(Regex("\\|[:\\s-|]+\\|"))) {
480+
// Note: In the character class, '-' must be at the end to avoid being interpreted as a range
481+
val dataRows = if (tableLines.size > 2 && tableLines[1].trim().matches(Regex("\\|[:\\s|\\-]+\\|"))) {
481482
tableLines.drop(2)
482483
} else {
483484
tableLines.drop(1)

mpp-core/src/jvmTest/kotlin/cc/unitmesh/devins/document/docql/DocQLCodeQueryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ class DocQLCodeQueryTest {
157157
)
158158

159159
val parsedFile = parser.parse(file, sampleKotlinCode) as DocumentFile
160-
160+
161161
// Execute $.code.function("execute")
162162
val query = parseDocQL("$.code.function(\"execute\")")
163163
val executor = DocQLExecutor(parsedFile, parser)
164164
val result = executor.execute(query)
165-
165+
166166
assertTrue(result is DocQLResult.Chunks)
167167
val chunks = result as DocQLResult.Chunks
168168
assertTrue(chunks.totalCount >= 1)

0 commit comments

Comments
 (0)