fix(api): cterm type in highlight keyset #37802

Problem: cterm field in Dict(highlight) is declared as Union(Integer, String)
but it actually expects a Dict(highlight_cterm).

Solution: change cterm type to DictAs(highlight__cterm) and simplify the
handling in dict2hlattrs since type validation and empty array compat are
already handled by api_dict_to_keydict.
This commit is contained in:
glepnir
2026-02-10 19:05:53 +08:00
committed by GitHub
parent 31c45f1aa4
commit b7070778b9
3 changed files with 4 additions and 12 deletions

View File

@@ -308,7 +308,7 @@ error('Cannot require a meta file')
--- @field altfont? boolean
--- @field nocombine? boolean
--- @field default? boolean
--- @field cterm? integer|string
--- @field cterm? vim.api.keyset.highlight_cterm
--- @field foreground? integer|string
--- @field fg? integer|string
--- @field background? integer|string

View File

@@ -181,7 +181,7 @@ typedef struct {
Boolean altfont;
Boolean nocombine;
Boolean default_ DictKey(default);
Union(Integer, String) cterm;
DictAs(highlight_cterm) cterm;
Union(Integer, String) foreground;
Union(Integer, String) fg;
Union(Integer, String) background;

View File

@@ -1089,10 +1089,10 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
}
// Handle cterm attrs
if (dict->cterm.type == kObjectTypeDict) {
if (HAS_KEY_X(dict, cterm)) {
Dict(highlight_cterm) cterm[1] = KEYDICT_INIT;
if (!api_dict_to_keydict(cterm, KeyDict_highlight_cterm_get_field,
dict->cterm.data.dict, err)) {
dict->cterm, err)) {
return hlattrs;
}
@@ -1109,14 +1109,6 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
CHECK_FLAG(cterm, cterm_mask, strikethrough, , HL_STRIKETHROUGH);
CHECK_FLAG(cterm, cterm_mask, altfont, , HL_ALTFONT);
CHECK_FLAG(cterm, cterm_mask, nocombine, , HL_NOCOMBINE);
} else if (dict->cterm.type == kObjectTypeArray && dict->cterm.data.array.size == 0) {
// empty list from Lua API should clear all cterm attributes
// TODO(clason): handle via gen_api_dispatch
cterm_mask_provided = true;
} else if (HAS_KEY_X(dict, cterm)) {
VALIDATE_EXP(false, "cterm", "Dict", api_typename(dict->cterm.type), {
return hlattrs;
});
}
#undef CHECK_FLAG