import type { AutocompleteItem, AutocompleteProvider, AutocompleteSuggestions } from '@earendil-works/pi-tui'; import type { RefMeta } from '../../../core/runtime/broker-protocol.js'; /** The caret's classification for completion purposes. `null` means the caret * is not touching any slash token at all (every other autocomplete mode — * file, `@`, etc. — is unaffected and this provider fully delegates). */ export type RefCompletionContext = { kind: 'leading'; startCol: number; endCol: number; prefix: string; } | { kind: 'ref'; startCol: number; endCol: number; prefix: string; }; /** * Classify the slash token (if any) touching the caret at * `(cursorLine, cursorCol)` in the editor's logical `lines`. Joins the lines * with `\n` (the editor's own logical-text convention — no grammar character * is `\n`, so a token can never straddle a line boundary) and delegates the * actual token detection to the shared `findRefTokenAtCaret`. * * `kind: 'leading'` means the token's `/` sits at the very start of the whole * message (global offset 0) — the existing command-only leading-completion * context, which this provider must not touch. Anything else — including a * `/` at the start of a LATER logical line, where the preceding joined-text * character is `\n`, not "start of input" — is `kind: 'ref'`. * * Returns `null` when the caret is not touching a token at all: it is not at * a token-starting `/` (offset zero or after ASCII whitespace only), it is * after non-whitespace, or it has moved past the end of the grammar run. */ export declare function findRefCompletionContext(lines: readonly string[], cursorLine: number, cursorCol: number): RefCompletionContext | null; /** * Wraps an existing command-only `AutocompleteProvider` (in practice always a * `CombinedAutocompleteProvider`) so that: * * - Leading-command context (`kind: 'leading'`) and every non-ref context * (`context === null`, e.g. file/`@` completion) delegate verbatim — byte- * for-byte unchanged command/file/`@` completion. * - A non-leading ref context (`kind: 'ref'`) is served entirely from the * supplied `refs` inventory instead: case-sensitive prefix filtering by the * typed surface form, `shortForm` as the row description, and a completion * that replaces only the detected token range with no trailing separator. * * Refs are never merged into the wrapped provider's command list, so leading * `/` completion always remains commands-only even when a ref shares a name * with something in `refs`. */ export declare class RefAwareAutocompleteProvider implements AutocompleteProvider { private readonly refs; private readonly refNames; private readonly delegate; constructor(refs: ReadonlyArray, delegate: AutocompleteProvider); /** Pass through unchanged — pi-tui's editor explicitly discards `/` as a * trigger character regardless, and `CombinedAutocompleteProvider` doesn't * declare any of its own, so this is normally `undefined`. */ get triggerCharacters(): string[] | undefined; getSuggestions(lines: string[], cursorLine: number, cursorCol: number, options: { signal: AbortSignal; force?: boolean; }): Promise; applyCompletion(lines: string[], cursorLine: number, cursorCol: number, item: AutocompleteItem, prefix: string): { lines: string[]; cursorLine: number; cursorCol: number; }; /** Admits forced (Tab) completion in a non-leading ref context, where * pi-tui's own leading-slash short-circuit doesn't apply (the current * line's text before the cursor doesn't start with `/`, so its Tab * handler routes through the forced-file path gated by this method). * Every other case delegates unchanged. */ shouldTriggerFileCompletion(lines: string[], cursorLine: number, cursorCol: number): boolean; }