aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/highlight_group.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-08-01 14:01:19 +0200
committerbfredl <bjorn.linse@gmail.com>2023-08-07 13:11:15 +0200
commit7bc93e0e2f246dd78026a3472d929a0fe450f70d (patch)
tree9e5b99830c3f08e0ffd75c7a0533b39033490a5b /src/nvim/highlight_group.c
parentc01e624b0762b24a4988bf9474a57d5b6278d180 (diff)
downloadrneovim-7bc93e0e2f246dd78026a3472d929a0fe450f70d.tar.gz
rneovim-7bc93e0e2f246dd78026a3472d929a0fe450f70d.tar.bz2
rneovim-7bc93e0e2f246dd78026a3472d929a0fe450f70d.zip
refactor(api): use typed keysets
Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata
Diffstat (limited to 'src/nvim/highlight_group.c')
-rw-r--r--src/nvim/highlight_group.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c
index 9ae928a0d2..de53545195 100644
--- a/src/nvim/highlight_group.c
+++ b/src/nvim/highlight_group.c
@@ -832,9 +832,11 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
struct {
int *dest; RgbValue val; Object name;
} cattrs[] = {
- { &g->sg_rgb_fg_idx, g->sg_rgb_fg, HAS_KEY(dict->fg) ? dict->fg : dict->foreground },
- { &g->sg_rgb_bg_idx, g->sg_rgb_bg, HAS_KEY(dict->bg) ? dict->bg : dict->background },
- { &g->sg_rgb_sp_idx, g->sg_rgb_sp, HAS_KEY(dict->sp) ? dict->sp : dict->special },
+ { &g->sg_rgb_fg_idx, g->sg_rgb_fg,
+ HAS_KEY(dict, highlight, fg) ? dict->fg : dict->foreground },
+ { &g->sg_rgb_bg_idx, g->sg_rgb_bg,
+ HAS_KEY(dict, highlight, bg) ? dict->bg : dict->background },
+ { &g->sg_rgb_sp_idx, g->sg_rgb_sp, HAS_KEY(dict, highlight, sp) ? dict->sp : dict->special },
{ NULL, -1, NIL },
};
@@ -1563,19 +1565,12 @@ static bool hlgroup2dict(Dictionary *hl, NS ns_id, int hl_id, Arena *arena)
Dictionary ns_get_hl_defs(NS ns_id, Dict(get_highlight) *opts, Arena *arena, Error *err)
{
- Boolean link = api_object_to_bool(opts->link, "link", true, err);
+ Boolean link = GET_BOOL_OR_TRUE(opts, get_highlight, link);
int id = -1;
- if (opts->name.type != kObjectTypeNil) {
- VALIDATE_T("highlight name", kObjectTypeString, opts->name.type, {
- goto cleanup;
- });
- String name = opts->name.data.string;
- id = syn_check_group(name.data, name.size);
- } else if (opts->id.type != kObjectTypeNil) {
- VALIDATE_T("highlight id", kObjectTypeInteger, opts->id.type, {
- goto cleanup;
- });
- id = (int)opts->id.data.integer;
+ if (HAS_KEY(opts, get_highlight, name)) {
+ id = syn_check_group(opts->name.data, opts->name.size);
+ } else if (HAS_KEY(opts, get_highlight, id)) {
+ id = (int)opts->id;
}
if (id != -1) {