diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-08-01 14:01:19 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-08-07 13:11:15 +0200 |
commit | 7bc93e0e2f246dd78026a3472d929a0fe450f70d (patch) | |
tree | 9e5b99830c3f08e0ffd75c7a0533b39033490a5b /src/nvim/api/options.c | |
parent | c01e624b0762b24a4988bf9474a57d5b6278d180 (diff) | |
download | rneovim-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/api/options.c')
-rw-r--r-- | src/nvim/api/options.c | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 3d42f60940..e33cb72e8d 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -8,6 +8,7 @@ #include "nvim/api/options.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/autocmd.h" @@ -26,14 +27,11 @@ static int validate_option_value_args(Dict(option) *opts, char *name, int *scope, int *opt_type, void **from, char **filetype, Error *err) { - if (HAS_KEY(opts->scope)) { - VALIDATE_T("scope", kObjectTypeString, opts->scope.type, { - return FAIL; - }); - - if (!strcmp(opts->scope.data.string.data, "local")) { +#define HAS_KEY_X(d, v) HAS_KEY(d, option, v) + if (HAS_KEY_X(opts, scope)) { + if (!strcmp(opts->scope.data, "local")) { *scope = OPT_LOCAL; - } else if (!strcmp(opts->scope.data.string.data, "global")) { + } else if (!strcmp(opts->scope.data, "global")) { *scope = OPT_GLOBAL; } else { VALIDATE_EXP(false, "scope", "'local' or 'global'", NULL, { @@ -44,51 +42,40 @@ static int validate_option_value_args(Dict(option) *opts, char *name, int *scope *opt_type = SREQ_GLOBAL; - if (filetype != NULL && HAS_KEY(opts->filetype)) { - VALIDATE_T("scope", kObjectTypeString, opts->filetype.type, { - return FAIL; - }); - - *filetype = opts->filetype.data.string.data; + if (filetype != NULL && HAS_KEY_X(opts, filetype)) { + *filetype = opts->filetype.data; } - if (HAS_KEY(opts->win)) { - VALIDATE_T_HANDLE("win", kObjectTypeWindow, opts->win.type, { - return FAIL; - }); - + if (HAS_KEY_X(opts, win)) { *opt_type = SREQ_WIN; - *from = find_window_by_handle((int)opts->win.data.integer, err); + *from = find_window_by_handle(opts->win, err); if (ERROR_SET(err)) { return FAIL; } } - if (HAS_KEY(opts->buf)) { - VALIDATE_T_HANDLE("buf", kObjectTypeBuffer, opts->buf.type, { - return FAIL; - }); - + if (HAS_KEY_X(opts, buf)) { *scope = OPT_LOCAL; *opt_type = SREQ_BUF; - *from = find_buffer_by_handle((int)opts->buf.data.integer, err); + *from = find_buffer_by_handle(opts->buf, err); if (ERROR_SET(err)) { return FAIL; } } - VALIDATE((!HAS_KEY(opts->filetype) - || !(HAS_KEY(opts->buf) || HAS_KEY(opts->scope) || HAS_KEY(opts->win))), + VALIDATE((!HAS_KEY_X(opts, filetype) + || !(HAS_KEY_X(opts, buf) || HAS_KEY_X(opts, scope) || HAS_KEY_X(opts, win))), "%s", "cannot use 'filetype' with 'scope', 'buf' or 'win'", { return FAIL; }); - VALIDATE((!HAS_KEY(opts->scope) || !HAS_KEY(opts->buf)), "%s", + VALIDATE((!HAS_KEY_X(opts, scope) || !HAS_KEY_X(opts, buf)), "%s", "cannot use both 'scope' and 'buf'", { return FAIL; }); - VALIDATE((!HAS_KEY(opts->win) || !HAS_KEY(opts->buf)), "%s", "cannot use both 'buf' and 'win'", { + VALIDATE((!HAS_KEY_X(opts, win) || !HAS_KEY_X(opts, buf)), + "%s", "cannot use both 'buf' and 'win'", { return FAIL; }); @@ -111,6 +98,7 @@ static int validate_option_value_args(Dict(option) *opts, char *name, int *scope } return OK; +#undef HAS_KEY_X } /// Create a dummy buffer and run the FileType autocmd on it. |