Skip to content

Commit 8a917d8

Browse files
committed
feat(search): limit ripgrep results and improve formatting
- Add result count display and limit output to first 30 results - Improve code formatting in RipgrepSearchInsCommand - Update documentation with regex usage tips
1 parent 66a355f commit 8a917d8

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

core/src/main/kotlin/cc/unitmesh/devti/agent/tool/search/RipgrepSearcher.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,23 @@ object RipgrepSearcher {
174174
return cmd
175175
}
176176

177-
private fun formatResults(results: MutableList<RipgrepSearchResult>, basePath: String): String {
177+
private fun formatResults(searchResults: MutableList<RipgrepSearchResult>, basePath: String): String {
178178
val output = StringBuilder()
179179
val grouped: MutableMap<String?, MutableList<RipgrepSearchResult?>?> =
180180
LinkedHashMap<String?, MutableList<RipgrepSearchResult?>?>()
181181

182+
var results = searchResults
183+
output.append("Total results: ").append(results.size)
184+
if (results.size > 30) {
185+
results = results.subList(0, 30)
186+
output.append("Too many results, only show first 30 results\n")
187+
}
188+
182189
for (result in results) {
183190
val relPath = getRelativePath(basePath, result.filePath!!)
184191
grouped.computeIfAbsent(relPath) { k: String? -> ArrayList<RipgrepSearchResult?>() }!!.add(result)
185192
}
186-
187-
output.append("Total results: ").append(results.size).append("\n```bash\n")
193+
output.append("\n```bash\n")
188194
for (entry in grouped.entries) {
189195
output.append("## filepath: ").append(entry.key).append("\n")
190196
val filePath = Paths.get(basePath, entry.key)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import cc.unitmesh.devti.agent.tool.search.RipgrepSearcher
66
import com.intellij.openapi.project.Project
77

88
/// https://github.com/MituuZ/fuzzier
9-
class RipgrepSearchInsCommand(
10-
val myProject: Project, private val scope: String, val text: String?,
11-
) : InsCommand {
9+
class RipgrepSearchInsCommand(val myProject: Project, private val scope: String, val text: String?) : InsCommand {
1210
override val commandName: BuiltinCommand = BuiltinCommand.RIPGREP_SEARCH
1311

1412
override fun isApplicable(): Boolean {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
支持 Regex 的全局搜索
2-
/ripgrepSearch:.*AutoDev.*
2+
/ripgrepSearch:.*AutoDev.*
3+
优化使用 Regex 方式,诸如使用 /s 替换空格

0 commit comments

Comments
 (0)