fix: 修复 @ typeahead 文件搜索无结果的问题

execa 新版将 signal 选项重命名为 cancelSignal,导致 execFileNoThrowWithCwd
调用 git ls-files 时抛出 TypeError,文件索引始终为空。同时改进了
FileIndex 的模糊匹配算法,从多个词边界起始位置评分取最优,提升搜索排名质量。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-01 17:11:09 +08:00
parent 8b63e54e94
commit 221fb6eb05
3 changed files with 83 additions and 41 deletions

View File

@@ -253,15 +253,14 @@ async function getFilesUsingGit(
logForDebugging(`[FileIndex] getFilesUsingGit called`)
// Check if we're in a git repo. findGitRoot is LRU-memoized per path.
const repoRoot = findGitRoot(getCwd())
const cwd = getCwd()
const repoRoot = findGitRoot(cwd)
if (!repoRoot) {
logForDebugging(`[FileIndex] not a git repo, returning null`)
return null
}
try {
const cwd = getCwd()
// Get tracked files (fast - reads from git index)
// Run from repoRoot so paths are relative to repo root, not CWD
const lsFilesStart = Date.now()
@@ -634,7 +633,9 @@ function findMatchingFiles(
*/
const REFRESH_THROTTLE_MS = 5_000
export function startBackgroundCacheRefresh(): void {
if (fileListRefreshPromise) return
if (fileListRefreshPromise) {
return
}
// Throttle only when a cache exists — cold start must always populate.
// Refresh immediately when .git/index mtime changed (tracked files).