refactor(options): rename, simplify

This commit is contained in:
Justin M. Keyes
2026-07-24 13:03:31 +02:00
parent 9604c758b3
commit c244a4bace
4 changed files with 9 additions and 15 deletions

View File

@@ -729,19 +729,15 @@ local function gen_keysets(output_file)
end
write('} OptKeyDict;')
-- Dispatch from option index to its keyset handle (opt_dict_info); NULL for non-dict options.
-- Dispatch from option index to its dict schema (opt_dict_schema); NULL for non-dict options.
write('')
write('static inline const OptDictInfo *opt_dict_info(OptIndex opt_idx)')
write('static inline const OptDictSchema *opt_dict_schema(OptIndex opt_idx)')
write('{')
write(' switch (opt_idx) {')
for _, s in ipairs(struct_opts) do
write((' case %s: {'):format(s.enum))
write(
(' static const OptDictInfo info = { %s_get_field, %s_table, opt_%s_schema,'):format(
s.kd,
s.abbr,
s.abbr
)
(' static const OptDictSchema info = { %s_get_field, opt_%s_schema,'):format(s.kd, s.abbr)
)
write((' sizeof(%s) };'):format(s.kd))
write(' return &info;')

View File

@@ -3340,7 +3340,7 @@ OptIndex find_option(const char *const name)
/// canonical ":set" string; reified on-demand (`opt_keyset()`) for validation and applying.
bool is_dict_option(OptIndex opt_idx)
{
return opt_dict_info(opt_idx) != NULL;
return opt_dict_schema(opt_idx) != NULL;
}
/// Free an allocated OptVal.
@@ -4144,7 +4144,7 @@ static const char *set_option(const OptIndex opt_idx, OptVal value, int opt_flag
// Every set path for a dict option (":set", the API, Vimscript, a merge) funnels through here as a
// ":set" string. Validate it once.
if (value.type == kOptValTypeString && is_dict_option(opt_idx)) {
errmsg = opt_strings_check(value.data.string.data, opt_dict_info(opt_idx)->schema, errbuf,
errmsg = opt_strings_check(value.data.string.data, opt_dict_schema(opt_idx)->schema, errbuf,
errbuflen);
if (errmsg != NULL) {
optval_free(value);

View File

@@ -93,14 +93,12 @@ typedef struct {
const char **enum_values; ///< kOptSchemaEnum: NULL-terminated valid values; else NULL
} OptSchemaItem;
/// Per-option handle for a dict option ("schema" in options.lua), generated by
/// `opt_dict_info()`. NULL from `opt_dict_info()` means the option is not a dict option.
/// Schema for a dict option (`schema.dict` in options.lua).
typedef struct {
FieldHashfn get_field; ///< Keyset perfect-hash lookup, for opt_fill().
const KeySetLink *table; ///< Field layout, for freeing a keyset's `String` fields.
const OptSchemaItem *schema; ///< Grammar, for opt_strings_check() validation.
size_t size; ///< sizeof the keyset, for allocation.
} OptDictInfo;
size_t size; ///< sizeof the keyset, for opt_keyset() storage.
} OptDictSchema;
/// :set operator types
typedef enum {

View File

@@ -2355,7 +2355,7 @@ void *opt_keyset(const char *value, OptIndex opt_idx, void *keyset)
if (keyset == NULL) {
keyset = &shared;
}
const OptDictInfo *si = opt_dict_info(opt_idx);
const OptDictSchema *si = opt_dict_schema(opt_idx);
memset(keyset, 0, si->size);
if (value != NULL) {
opt_fill(value, si->get_field, keyset);