Skip to content

Commit b2440e9

Browse files
committed
core: improve file search reliability and performance
1 parent 1256244 commit b2440e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/opencode/src/file/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export namespace File {
8888
let current = file
8989
while (true) {
9090
const dir = path.dirname(current)
91+
if (dir === ".") break
9192
if (dir === current) break
9293
current = dir
9394
if (set.has(dir)) continue
@@ -113,6 +114,10 @@ export namespace File {
113114
}
114115
})
115116

117+
export function init() {
118+
state()
119+
}
120+
116121
export async function status() {
117122
const project = Instance.project
118123
if (project.vcs !== "git") return []
@@ -242,10 +247,13 @@ export namespace File {
242247
}
243248

244249
export async function search(input: { query: string; limit?: number }) {
250+
log.info("search", { query: input.query })
245251
const limit = input.limit ?? 100
246252
const result = await state().then((x) => x.files())
247-
const items = input.query ? [...result.files, ...result.dirs] : [...result.dirs]
253+
if (!input.query) return result.dirs.toSorted()
254+
const items = [...result.files, ...result.dirs]
248255
const sorted = fuzzysort.go(input.query, items, { limit: limit }).map((r) => r.target)
256+
log.info("search", { query: input.query, results: sorted.length })
249257
return sorted
250258
}
251259
}

0 commit comments

Comments
 (0)