Skip to content

Commit e2ad8dc

Browse files
committed
fix: correct line info calculation in file command
- Fix LineInfo.fromString to handle single line references (L10) without requiring end line - Improve file content chunking message with clearer instructions - Make next chunk suggestion more accurate and only show when relevant - Enhance readability of file output message by including total line count
1 parent ee4e202 commit e2ad8dc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/FileInsCommand.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ class FileInsCommand(private val myProject: Project, private val prop: String) :
9090
val code = content.split("\n")
9191
.slice(0 until MAX_LINES)
9292
.joinToString("\n")
93+
94+
// 计算合理的下一块行范围建议
95+
val nextChunkStart = MAX_LINES + 1
96+
val nextChunkEnd = minOf(size, MAX_LINES * 2)
97+
98+
val suggestion = if (nextChunkEnd > nextChunkStart) {
99+
"\nUse `filename#L${nextChunkStart}-L${nextChunkEnd}` to get next chunk of lines."
100+
} else ""
93101

94-
val availableEndLine = minOf(size, MAX_LINES * 2)
95-
"File too long, only show first $MAX_LINES lines.\n$code\nUse `filename#L${MAX_LINES}-L${availableEndLine}` to get more lines."
102+
"File too long, only showing first $MAX_LINES lines of $size total lines.\n$code$suggestion"
96103
} else {
97104
content
98105
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/model/LineInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ data class LineInfo(
77
val endColumn: Int = 0
88
) {
99
companion object {
10-
private val regex = Regex("""L(\d+)(?:C(\d+))?(?:-L(\d+)(?:C(\d+))?)?""")
10+
private val regex = Regex("""L(\d+)(?:C(\d+))?(?:-L(\d+)(?:C(\d+))?)?""")
1111

1212
/**
1313
* Convert a string to a `TextRange`, if possible. The string should be in the format: "filepath#L1-L12",
@@ -21,7 +21,7 @@ data class LineInfo(
2121

2222
val startLine = matchResult.groupValues[1].toIntOrNull() ?: return null
2323
val startColumn = matchResult.groupValues[2].toIntOrNull() ?: 0
24-
val endLine = matchResult.groupValues[3].toIntOrNull() ?: return null
24+
val endLine = matchResult.groupValues[3].toIntOrNull() ?: startLine
2525
val endColumn = matchResult.groupValues[4].toIntOrNull() ?: 0
2626

2727
return LineInfo(startLine, endLine, startColumn, endColumn)

0 commit comments

Comments
 (0)