Skip to content

internals file search

github-actions[bot] edited this page Dec 1, 2026 · 1 revision

File search internals

User guide: Interactive mode.

Index and sources

Index (internal/filesearch/index.go) maintains snapshots for the file picker. NewIndex resolves the root with filepath.EvalSymlinks, retaining the original on failure. scan and pathCollector (internal/filesearch/scan.go) produce deduplicated root-relative paths with / separators and trailing / on directories.

scanGit (internal/filesearch/scan_git.go) streams git --no-optional-locks -C <root> ls-files -z -c -o --exclude-standard --deduplicate. Git's standard exclusions include gitignore files, .git/info/exclude, and global excludes. The collector derives ancestor directories from listed paths, so git alone does not list empty directories. A concurrent ls-files -z -d finds deleted tracked files for removal at final publication; if that command fails, they can remain. After a nonempty git listing, a separate walk includes gitignored .steiner content. If git fails or lists no entries, scan falls back to walkEntries (internal/filesearch/scan_walk.go), which uses fastwalk with Follow: false. The separate .steiner walk can also contribute directories.

The collector applies tool.WorkspaceExcluder with tool.FilePickerExcludePaths and tool.FilePickerAlwaysInclude (internal/tool/excluder.go) on top of the source. The latter includes .steiner despite built-in exclusions; the exact prefixes .steiner/tmp and .steiner/worktrees take precedence and remain excluded.

The first Refresh streams append-only items under one Gen. Completion publishes a sorted snapshot under a new Gen. Later refreshes build separately and swap on completion, retaining the old snapshot while scanning. Streaming notifications are coalesced and throttled to 50 ms; completion forces a notification. maxIndexEntries caps a scan at 500,000 entries and Snapshot.Truncated reports truncation. Refresh is a no-op during a scan or after Close; Close cancels and waits for a scan and closes the update channel. There is no filesystem watcher: the TUI requests a refresh when the picker opens (internal/tui/file_picker_keys.go, internal/tui/file_search_cmds.go).

Matching and cache

Query preparation, scoring and match positions belong to internal/fuzzymatch; see Fuzzy matching internals. Searcher (internal/filesearch/search.go) builds one fuzzymatch.Pattern per request and uses Pattern.Key as the cache key. Item (internal/filesearch/item.go) holds the path and its prepared fuzzymatch.Text.

Searcher.scan divides candidates into chunks of 4096 across up to GOMAXPROCS workers. Each worker takes its own fuzzymatch.Scratch, scores with Pattern.Score, collects all matching indexes and retains a bounded heap of top ranks. Nonempty-query ranking is score descending, boost rank ascending, path rune length ascending, then index ascending. An empty query orders boosted paths by boost rank and index, then remaining paths by index.

The 16-entry LRU query cache is scoped to Gen and stores all matched indexes, not just the result limit. A longer query can reuse the longest cached prefix's matches and scan any newly appended tail. Cancellation is checked between chunks; cancelled searches are not cached.

TUI integration

internal/tui/file_search_cmds.go dispatches asynchronous searches with a limit of 500, serializes access to one Searcher, and guards results by sequence and root. Boosts rank accepted paths by recency, followed by git-changed paths. filePickerOverlay.View (internal/tui/file_picker.go) calls fuzzymatch.Positions only for visible rows. The TUI closes the index on exit (internal/tui/exit_flow.go).

Clone this wiki locally