mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-14 23:21:19 +00:00
Sort file search results shortest to longest (#1849)
This commit is contained in:
parent
dca4563b9a
commit
4f6dd74c29
1 changed files with 5 additions and 22 deletions
|
|
@ -3,7 +3,7 @@ import * as path from "path"
|
|||
import * as fs from "fs"
|
||||
import * as childProcess from "child_process"
|
||||
import * as readline from "readline"
|
||||
import { Fzf } from "fzf"
|
||||
import { byLengthAsc, Fzf } from "fzf"
|
||||
import { getBinPath } from "../ripgrep"
|
||||
|
||||
async function executeRipgrepForFiles(
|
||||
|
|
@ -123,22 +123,16 @@ export async function searchWorkspaceFiles(
|
|||
// Run fzf search on all items
|
||||
const fzf = new Fzf(searchItems, {
|
||||
selector: (item) => item.searchStr,
|
||||
tiebreakers: [byLengthAsc],
|
||||
limit: limit,
|
||||
})
|
||||
|
||||
// Get all matching results from fzf
|
||||
const fzfResults = fzf.find(query)
|
||||
|
||||
// First, sort all results by path length (shortest first)
|
||||
fzfResults.sort((a, b) => {
|
||||
return a.item.original.path.length - b.item.original.path.length
|
||||
})
|
||||
|
||||
// Take the top N (limit) shortest results
|
||||
const shortestResults = fzfResults.slice(0, limit).map((result) => result.item.original)
|
||||
const fzfResults = fzf.find(query).map((result) => result.item.original)
|
||||
|
||||
// Verify types of the shortest results
|
||||
const verifiedResults = await Promise.all(
|
||||
shortestResults.map(async (result) => {
|
||||
fzfResults.map(async (result) => {
|
||||
const fullPath = path.join(workspacePath, result.path)
|
||||
// Verify if the path exists and is actually a directory
|
||||
if (fs.existsSync(fullPath)) {
|
||||
|
|
@ -153,17 +147,6 @@ export async function searchWorkspaceFiles(
|
|||
}),
|
||||
)
|
||||
|
||||
// Final sort to put directories first within the shortest results
|
||||
verifiedResults.sort((a, b) => {
|
||||
if (a.type === "folder" && b.type !== "folder") {
|
||||
return -1
|
||||
}
|
||||
if (a.type !== "folder" && b.type === "folder") {
|
||||
return 1
|
||||
}
|
||||
return 0 // Keep original sorting by path length
|
||||
})
|
||||
|
||||
return verifiedResults
|
||||
} catch (error) {
|
||||
console.error("Error in searchWorkspaceFiles:", error)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue