Skip to main content

Module picker_sources

Module picker_sources 

Source
Expand description

First-party picker source generators – renderer-neutral; live in lattice-picker next to the PickerSourceGenerator trait and the PickerRegistry they register against. Symmetric with how feature crates already organise their sources (lattice_snippet::picker_sources, future lattice_lsp::picker_sources).

Each source’s state is reachable through PickerContext (the snapshot passed to init / accept) or via an Arc-cloned registry handle captured at construction (CommandsSource -> CommandRegistry, GrepSource -> ConfigRegistry). The trait surface stays state-handle-free.

Slice 5.7.B.0 migrated this module out of lattice-ui-tui. The walk_files_for_picker helper (file-system walk for :picker files) lives here too – it has no renderer dependency, and the only consumer today is FilesSource; the earlier ui-tui location was an accident of where the picker first landed.

Structs§

BuffersSource
:picker buffers. Walks ctx.buffers and emits one row per registered buffer, with (current) marginalia on the active one. Active buffer floats to the bottom of the list so the alternate-buffer convention (<C-^>-style) keeps working: the initial selection lands on the alternate, not on the buffer the user already sees.
CommandHistorySource
:picker history — also reached via the q: Normal chord and the :history ex-command (MB.3). Walks ctx.command_history (the App’s command-line history ring, stored oldest-first) and emits one row per past command, newest first. <CR> loads the chosen command into the editable : line via RoutingPayload::LoadCommandLine — it does not execute; the user tweaks (or <C-x><C-e> expands) then <CR>s. The modern replacement for vim’s command-line window: fuzzy-filter past commands instead of scrolling a scratch buffer (docs/dev/architecture/rich-minibuffer.md §4).
CommandsSource
:picker commands. Walks the App’s CommandRegistry and emits one row per registered ex-command (motions, operators, etc. are not user-invocable through this surface and stay out). Captures an Arc<CommandRegistry> at construction time – the registry doesn’t live on PickerContext because it’s static App-wide state, not per-invocation snapshot data.
DirPickSource
PC.9: dir-pick — FilePickSource’s directory peer. Browse to a directory and supply its path as a value.
FilePickSource
:picker file-pick [root]. MG.53.e — the same walk as FilesSource, accepting to a value instead of to an open buffer.
FilesSource
GrepSource
JumpsSource
:picker jumps. Walks ctx.position_history (unified jump-list + mark-ring per §5.1.1) and emits one row per entry, newest first. Accept emits JumpInBuffer so the host’s apply translator handles “activate buffer + position cursor” uniformly. MRU is correctly absent for these rows – routing_identity returns None for JumpInBuffer because coordinates drift.
LinesSource
:picker lines. Walks the active buffer’s rope and emits one row per logical line, displayed as <lineno>: <text>. Accept jumps the cursor to that line via RoutingPayload::JumpInBuffer. The buffer_id is captured at picker-open so a sibling hover-preview can’t accidentally redirect the jump.
MarksSource
:picker marks. Walks ctx.marks (sorted by name in build_picker_context) and emits one row per set mark. Accept emits JumpToMark { name } which the host resolves through do_jump_mark – same path the ` motion uses, so cursor placement + position-history push match keyboard-driven behavior. MRU will key on mark:<name> automatically when slice 14 lands.
OutlineSource
:picker outline. Tree-sitter-driven symbol outline for the active buffer. Reads ctx.active_buffer.syntax_symbols (pre-collected by the host via Syntax::collect_symbol_locations) and emits one row per symbol, sorted by source position. Accept jumps the cursor to the symbol via JumpInBuffer.
PaneBufferHistorySource
PBH.5: :picker pane-buffer-history — also reached via :history pane-buffers. Walks the ACTIVE pane’s buffer trail (ctx.pane_buffer_history, oldest-first as stored) and emits one row per stop, newest first, marking the entry the walk cursor currently sits on.
RecentFilesSource
:picker recent. Walks ctx.recent_files (MRU, newest first) and emits one row per path. Empty MRU returns Err("no recent files") which the host echoes.
RegistersSource
:picker registers. Walks ctx.registers ((name, preview) pairs already prepared by the host’s build_picker_context) and emits one row per register. Accept emits PasteRegister { name }; the host routes through do_paste with the chosen register pre-selected.
SearchHistorySource
MB.5: :picker search-history — also reached via the q/ / q? Normal chords and :history search. Walks ctx.search_history (the App’s search-line history ring, stored oldest-first) and emits one row per past search term, newest first. <CR> loads the chosen term into the editable / line via RoutingPayload::LoadSearchLine — it does not execute.
YankRingSource
:picker yank-ring. YR.4 — the yank ring and the live named registers, in one list.

Constants§

DIR_PICK_SOURCE
The source id, shared by the generator and every declaration that names it.
FILE_PICKER_MAX_ENTRIES
Hard cap on the file-picker walker’s emitted entry count. At this scale the host’s fuzzy matcher stays well inside the per-keystroke frame budget; larger trees fall back to ripgrep- style live filtering via :grep (P.10) or :Filetree’s per-directory lazy walk.
FILE_PICK_SOURCE
The source id, shared by the generator and every declaration that names it — one constant so a rename cannot leave a transient pointing at a source that no longer exists.
PARENT_ROW_DISPLAY
What PP.1’s go-up row displays — and, since PP.3, how it is RECOGNISED.
YANK_RING_SOURCE

Traits§

GrepPreviewHighlighter
:picker grep <pattern>. Shells out to a configurable backend (rg, ag, grep, or auto-detected at invocation time) and walks its output line-by-line.

Functions§

first_party_generators
Convenience: build the first-party source generators as Arc<dyn PickerSourceGenerator> ready to register against a PickerRegistry. Used by App::new (and a future host- owned Editor::boot) to boot the registry. Sources that need App-wide state captured at construction (e.g. CommandsSource -> CommandRegistry, GrepSource -> ConfigRegistry) take the relevant Arc here so the trait surface stays state-handle-free.
walk_files_for_picker
Walk root recursively (BFS) and return the absolute paths of every regular file (with its metadata), capped at FILE_PICKER_MAX_ENTRIES.
warm_files_cache
Pre-walk root into the session cache so the first :files open is instant. The host calls this from a background thread at boot (and on project change); FilesSource::init also calls it to refresh a warm entry. Runs the same walk_files_for_picker — off whatever thread the caller spawns it on, never the UI thread.

Type Aliases§

WalkedFile
One walked file: its absolute path plus the metadata gathered during the walk (None when the entry could not be stat’d). Returned by walk_files_for_picker so a source’s init builds candidates + their marginalia without a second stat pass.