/* @file completion for the editor (atfile.c), after Pi's * CombinedAutocompleteProvider (reference/pi/packages/tui/src/autocomplete.ts): * "@" at the start of a word plus a partial path lists workspace files and * folders. No I/O but reading directories; the menu and editing live in app.c. */ #ifndef PIC_TUI_ATFILE_H #define PIC_TUI_ATFILE_H #include #define ATFILE_VALUE_MAX 600 typedef struct { char value[ATFILE_VALUE_MAX]; /* what replaces the token: @path, @path/ (folder), @"a b" (needs quotes) */ char label[256]; /* shown: name (with a trailing "/" for a folder) and its path */ int is_dir; } atfile_item; /* The @-token ending at CURSOR in TEXT (a word starting with "@", or an * unclosed @"...). Returns 1 and sets *start (offset of the "@"), writes the * path typed so far (no "@", no quote) to query and sets *quoted; 0 when the * cursor is not in one. */ int atfile_token(const char *text, size_t cursor, size_t *start, char *query, size_t qcap, int *quoted); /* Up to CAP completions of QUERY under ROOT, best first: names fuzzy-matched * (tui_fuzzy_match) anywhere in the tree, exact > prefix > substring > * fuzzy, folders ahead of equals, shallower first. A QUERY with a "/" scopes * the walk to that folder (relative to ROOT, absolute, or ~/). The walk is * breadth-first and bounded (ATFILE_MAX_ENTRIES / ATFILE_MAX_DEPTH), skips * .git and node_modules (atfile_skip in atfile.c is the one place to add * ignore rules) and follows symlinks. */ size_t atfile_candidates(const char *root, const char *query, int quoted, atfile_item *out, size_t cap); #define ATFILE_MAX_ENTRIES 20000 #define ATFILE_MAX_DEPTH 8 #endif