Repository navigation
perf(tui): cache and speed up @ file-reference completion - #808
alejandro-ao wants to merge 4 commits into
Conversation
Replace the per-keystroke Path.iterdir walk with an os.scandir walker that tracks relative paths directly and detects symlink cycles. Add a FileReferenceIndex that serves the first snapshot synchronously, then keeps later snapshots current with a TTL and a background refresh callback. Preserve substring matching, ignored directories, ordering, the 50-item cap, and external ../ completion. Existing completion tests keep exercising the pure on-demand walk.
Review findingsReviewed at
Validation: |
Address review findings on the file-reference index: - Track ancestor inodes per traversal branch so symlinked aliases keep their own completions while cycles still terminate. - Preserve the selected completion across background rebuilds and do not reopen a closed picker. - Resolve the cached snapshot lazily so shell paths, /model arguments, and external ../ references never trigger a workspace scan. - Force a background refresh when a tool or terminal command finishes during an active workspace file search. - Retry scans invalidated mid-flight, keep the last good snapshot on refresh failure, and propagate root scan errors so failures cannot publish an empty snapshot as fresh.
|
Addressed all six findings in
Local checks: |
Handle `@~` and `@~/...` in the same external-path completion branch as `@../...`: expand the home directory, list one directory level, apply the ignored-directory filter, preserve the `~/` prefix in the display, and cap results at the existing limit. Home references do not need the workspace index, so they remain outside the cached snapshot and avoid a workspace scan.
Follow-up reviewReviewed
The published TUI guide also does not yet document the new Validation: |
Address the follow-up review: - Escape spaces in file-reference displays and teach the tokenizer to treat backslash-escaped whitespace as part of the token, so completion can descend into directories such as Application Support. - Normalize home-relative prefixes before generic parent-path handling, collapse duplicate slashes and dot segments, and resolve `@~/..` against the home tree instead of the workspace. - Return scan completeness from the walker. Missing roots and unreadable nested directories now leave the index stale so the last good snapshot survives. - Rebuild an active `@` search after a refresh even when it currently has zero results, instead of treating an empty result set as a dismissed picker. - Document `@~/` and escaped spaced paths in the TUI guide.
|
Addressed all four follow-up findings plus the docs gap in
Local: |
Summary
@file references in the TUI used to re-walk the entire workspace on every prompt text change. This PR makes the walk cheaper, caches it, and finishes the external-path behavior:Path.iterdirwalk with anos.scandirwalker that tracks relative paths as strings and detects symlink cycles per traversal branch.FileReferenceIndex, a stale-while-revalidate snapshot per workspace. The first request builds synchronously; later keystrokes filter cached entries and rebuild in a daemon thread when the TTL expires or a tool invalidates the index.build_completion_statelazily, so only an active workspace@reference resolves it.@~and@~/..., normalizes home prefixes before parent-path handling, and escapes spaces so completion can descend into directories such as@~/Application\ Support/.../completion.User experience
Measured on a 100,100-entry synthetic workspace:
@Typing
@no longer drops keystrokes or blocks the Textual event loop on large repositories. Background refreshes keep the current selection, failed or partial scans keep the previous suggestions, and zero-result searches update when a tool creates a matching file. Home-relative paths and paths containing spaces now complete and can be navigated further.Issue
Closes #463.
Note: #473 also changes the file-reference walk (
.gitignorefiltering). This PR replaces_iter_file_reference_pathswithscan_file_reference_entries; #473 will need a small rebase to apply its filtering in the new walker.Manual validation
tau.@and keep typing a filename prefix.@~/and confirm home-relative suggestions appear.@~/Applicationinto a home containingApplication Support/and confirm Tab inserts the escaped path and further completion works inside it.@newbeforenew.pyexists, then create the file with a tool; the suggestion should appear without another keystroke.uv run pytest,uv run ruff check .,uv run ruff format --check ., anduv run mypy.Tests
FileReferenceIndextests cover bootstrap, TTL refresh, forced refresh, invalidation, mid-flight invalidation, incomplete/failed scans, non-blocking stale reads, and close behavior.@search.2274 passed, 2 skipped.