/** * Inline completion for `/commands` and `@file` paths. * * Deliberately NOT an overlay. An overlay owns the keyboard, and completion has to * coexist with typing: the list narrows as characters arrive, and every key that * is not a completion gesture belongs to the composer. So this is a slot view plus * a key filter the runner consults first, and it disappears the moment the text * under the cursor stops looking like a completable token. * * What is completable is decided from the text BEHIND the cursor only. Completing * against text ahead of it would rewrite characters the user did not ask about, and * a token is not finished until the cursor leaves it. * @module dshline/completion */ import type { Composer, Key } from '@dshline/renderer'; import type { TuiSlotView } from './slots.ts'; /** * A candidate. * * `replace` is what the token becomes, complete with its sigil, so accepting is a * substitution rather than an assembly the caller has to get right. */ export interface Candidate { /** The full replacement for the typed token. */ readonly replace: string; /** What the row shows. */ readonly label: string; /** Optional trailing note, dimmed. */ readonly note?: string; } /** Where candidates come from, so the engine holds no opinion about the harness. */ export interface CompletionSources { /** * Commands available right now, for a line that begins with a slash. * @returns the command names, without their leading slash, and their summaries. */ commands(): readonly { readonly name: string; readonly description: string; }[]; /** * Values one command accepts as its argument, for a line that already names it. * * Asked of the runner rather than derived here, because what a command accepts * is a live fact: which reasoning levels exist depends on the route currently * selected, and which models exist depends on what the adapters advertise. * @param name - the command, without its leading slash. * @returns the offered values, in the order they should be listed. A value * may carry `aliases`: extra text a prefix matches against, which is never * what accepting the row inserts. * @throws nothing a caller must handle; a command with no arguments yields none. */ commandArguments(name: string): Promise; /** * Directory children for a path completion. * @param directory - the directory to list, relative to the workspace, or empty * for the workspace root. * @returns each child's name and whether it is itself a directory. * @throws nothing a caller must handle; an unreadable directory yields no entries. */ paths(directory: string): Promise; } /** One child of a listed directory, as completion offers it. */ export interface PathEntry { /** The child's own name, without its parent's path. */ readonly name: string; /** Whether the child is a directory, which is what keeps its separator. */ readonly directory: boolean; } /** Live completion state for one composer. */ export interface Completion { /** The slot view; contributes nothing while no candidates are offered. */ readonly view: TuiSlotView; /** * Recompute from the composer's current text. Async because a path completion * reads a directory. * @returns nothing; call the runner's redraw afterwards. */ refresh(): Promise; /** Whether candidates are being offered, and so whether keys are intercepted. */ readonly active: boolean; /** * Offer one keystroke to the completion. * @param key - the decoded keystroke. * @returns whether the completion consumed it. */ handleKey(key: Key): boolean; /** * Abandon any lookup still in flight and stop offering candidates, without * recomputing against the composer's current text. * * Used when the composer is replaced wholesale — a submitted line or a * recalled history entry — so a slow directory read cannot revive candidates * for text that no longer exists. `refresh()` must run again before anything * is offered. */ invalidate(): void; } /** * Wire completion to a composer. * @param composer - the buffer being edited; accepting a candidate rewrites it. * @param sources - where candidates come from. * @param redraw - asks the runner to redraw. * @param rowsBelow - fixed live rows the list must leave beneath itself. * @returns the live completion state. */ export declare function createCompletion(composer: Composer, sources: CompletionSources, redraw: () => void, rowsBelow?: () => number): Completion; //# sourceMappingURL=completion.d.ts.map