/* @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 <stddef.h>
#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);
/* One listed entry: its path from the listed folder (malloc'd), whether it
* is a folder, and its depth (1 for the folder's own entries). */
typedef struct {
char *path;
int is_dir;
int depth;
} atfile_found;
/* Lists BASE breadth-first, at most ATFILE_MAX_ENTRIES entries and
* ATFILE_MAX_DEPTH deep, without what the ignore files leave out: *OUT is
* malloc'd; the count. The interface asks pic's list_files command. */
typedef size_t (*atfile_lister)(void *ctx, const char *base, atfile_found **out);
/* Up to CAP completions of QUERY under ROOT, best first: names fuzzy-matched
* (tui_fuzzy_match) anywhere in the tree LIST gives, exact > prefix >
* substring > fuzzy, folders ahead of equals, shallower first. A QUERY with a
* "/" scopes the listing to that folder (relative to ROOT, absolute, or ~/). */
size_t atfile_candidates(const char *root, const char *query, int quoted, atfile_item *out, size_t cap,
atfile_lister list, void *ctx);
#define ATFILE_MAX_ENTRIES 20000
#define ATFILE_MAX_DEPTH 8
#endif