()
| 521 | * Returns a FileIndex populated for fast fuzzy search |
| 522 | */ |
| 523 | export async function getPathsForSuggestions(): Promise<FileIndex> { |
| 524 | const signal = AbortSignal.timeout(10_000) |
| 525 | const index = getFileIndex() |
| 526 | |
| 527 | try { |
| 528 | // Check project settings first, then fall back to global config |
| 529 | const projectSettings = getInitialSettings() |
| 530 | const globalConfig = getGlobalConfig() |
| 531 | const respectGitignore = |
| 532 | projectSettings.respectGitignore ?? globalConfig.respectGitignore ?? true |
| 533 | |
| 534 | const cwd = getCwd() |
| 535 | const [projectFiles, configFiles] = await Promise.all([ |
| 536 | getProjectFiles(signal, respectGitignore), |
| 537 | getClaudeConfigFiles(cwd), |
| 538 | ]) |
| 539 | |
| 540 | // Cache for mergeUntrackedIntoNormalizedCache |
| 541 | cachedConfigFiles = configFiles |
| 542 | |
| 543 | const allFiles = [...projectFiles, ...configFiles] |
| 544 | const directories = await getDirectoryNamesAsync(allFiles) |
| 545 | cachedTrackedDirs = directories |
| 546 | const allPathsList = [...directories, ...allFiles] |
| 547 | |
| 548 | // Skip rebuild when the list is unchanged. This is the common case |
| 549 | // during a typing session — git ls-files returns the same output. |
| 550 | const sig = pathListSignature(allPathsList) |
| 551 | if (sig !== loadedTrackedSignature) { |
| 552 | // Await the full build so cold-start returns complete results. The |
| 553 | // build yields every ~4ms so the UI stays responsive — user can keep |
| 554 | // typing during the ~120ms wait without input lag. |
| 555 | await index.loadFromFileListAsync(allPathsList).done |
| 556 | loadedTrackedSignature = sig |
| 557 | // We just replaced the merged index with tracked-only data. Force |
| 558 | // the next untracked merge to rebuild even if its own sig matches. |
| 559 | loadedMergedSignature = null |
| 560 | } else { |
| 561 | logForDebugging( |
| 562 | `[FileIndex] skipped index rebuild — tracked paths unchanged`, |
| 563 | ) |
| 564 | } |
| 565 | } catch (error) { |
| 566 | logError(error) |
| 567 | } |
| 568 | |
| 569 | return index |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Finds the common prefix between two strings |
no test coverage detected