Skip to content
docsv0.3.0

AutocompleteProviderInterface

Suggests completions for a text-input or editor field. The TUI analog of pi-tui's `AutocompleteProvider` interface. A provider answers two questions: "does the current text+cursor trigger a completion query?" (via {@see shouldTrigger()}) and "what completions match the query?" (via {@see suggestions()}). The renderer or key handler that owns the field calls these to populate a `select-list` overlay showing the matches. Implementations are expected to be cheap and synchronous — a provider is consulted on every keystroke when a completion window is open, so blocking I/O or expensive lookups should be offloaded by the caller, not baked into the contract. Pure in-memory providers (slash commands, a small file list) are the intended use case.

AutocompleteProviderInterface::shouldTrigger()

abstract public function shouldTrigger(string $text, int $cursor): bool

Whether the cursor at `$cursor` in `$text` should open a completion window. The provider decides what triggers a query — e.g. a slash command provider answers true when the cursor follows a `/` not preceded by a non-whitespace char, a file path provider answers true for `./`, `~/`, `../`, `@` prefixes.

Parameters

Parameters of shouldTrigger()
NameTypeDescription
$textstring
$cursorint

AutocompleteProviderInterface::suggestions()

abstract public function suggestions(string $text, int $cursor): array

Returns the completion matches for the query extracted from `$text` at `$cursor`. Each suggestion is a `{value, label, description?}` array shaped the same way as a `select-list` item, so the caller can hand the result straight to a `SelectListRenderer` overlay.

Parameters

Parameters of suggestions()
NameTypeDescription
$textstring
$cursorint