core: improve file search reliability and performance
This commit is contained in:
parent
125624489b
commit
b2440e92e7
1 changed files with 9 additions and 1 deletions
|
|
@ -88,6 +88,7 @@ export namespace File {
|
||||||
let current = file
|
let current = file
|
||||||
while (true) {
|
while (true) {
|
||||||
const dir = path.dirname(current)
|
const dir = path.dirname(current)
|
||||||
|
if (dir === ".") break
|
||||||
if (dir === current) break
|
if (dir === current) break
|
||||||
current = dir
|
current = dir
|
||||||
if (set.has(dir)) continue
|
if (set.has(dir)) continue
|
||||||
|
|
@ -113,6 +114,10 @@ export namespace File {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export function init() {
|
||||||
|
state()
|
||||||
|
}
|
||||||
|
|
||||||
export async function status() {
|
export async function status() {
|
||||||
const project = Instance.project
|
const project = Instance.project
|
||||||
if (project.vcs !== "git") return []
|
if (project.vcs !== "git") return []
|
||||||
|
|
@ -242,10 +247,13 @@ export namespace File {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function search(input: { query: string; limit?: number }) {
|
export async function search(input: { query: string; limit?: number }) {
|
||||||
|
log.info("search", { query: input.query })
|
||||||
const limit = input.limit ?? 100
|
const limit = input.limit ?? 100
|
||||||
const result = await state().then((x) => x.files())
|
const result = await state().then((x) => x.files())
|
||||||
const items = input.query ? [...result.files, ...result.dirs] : [...result.dirs]
|
if (!input.query) return result.dirs.toSorted()
|
||||||
|
const items = [...result.files, ...result.dirs]
|
||||||
const sorted = fuzzysort.go(input.query, items, { limit: limit }).map((r) => r.target)
|
const sorted = fuzzysort.go(input.query, items, { limit: limit }).map((r) => r.target)
|
||||||
|
log.info("search", { query: input.query, results: sorted.length })
|
||||||
return sorted
|
return sorted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue