Skip to content

Commit d6350a7

Browse files
authored
tweak: update ls tool to use rg (anomalyco#2367)
1 parent ae83138 commit d6350a7

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

  • packages/opencode/src/tool

packages/opencode/src/tool/ls.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Tool } from "./tool"
33
import * as path from "path"
44
import DESCRIPTION from "./ls.txt"
55
import { Instance } from "../project/instance"
6+
import { Ripgrep } from "../file/ripgrep"
67

78
export const IGNORE_PATTERNS = [
89
"node_modules/",
@@ -42,15 +43,8 @@ export const ListTool = Tool.define("list", {
4243
async execute(params) {
4344
const searchPath = path.resolve(Instance.directory, params.path || ".")
4445

45-
const glob = new Bun.Glob("**/*")
46-
const files = []
47-
48-
for await (const file of glob.scan({ cwd: searchPath, dot: true })) {
49-
if (IGNORE_PATTERNS.some((p) => file.includes(p))) continue
50-
if (params.ignore?.some((pattern) => new Bun.Glob(pattern).match(file))) continue
51-
files.push(file)
52-
if (files.length >= LIMIT) break
53-
}
46+
const ignoreGlobs = IGNORE_PATTERNS.map((p) => `!${p}*`).concat(params.ignore?.map((p) => `!${p}`) || [])
47+
const files = await Ripgrep.files({ cwd: searchPath, glob: ignoreGlobs, limit: LIMIT })
5448

5549
// Build directory structure
5650
const dirs = new Set<string>()

0 commit comments

Comments
 (0)