diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-14 18:13:02 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-09-14 18:57:35 -0700 |
commit | f2c75ef9b481e6c3b65f7b37a3c8e8afc5c73be3 (patch) | |
tree | 921c8355b1e089c989c83d19790bbcb68ea2cc08 /src/nvim/api/vim.c | |
parent | 2e0e592ea29ea7d2da333824a93aa543a6f7f390 (diff) | |
download | rneovim-f2c75ef9b481e6c3b65f7b37a3c8e8afc5c73be3.tar.gz rneovim-f2c75ef9b481e6c3b65f7b37a3c8e8afc5c73be3.tar.bz2 rneovim-f2c75ef9b481e6c3b65f7b37a3c8e8afc5c73be3.zip |
API: nvim_get_context: "opts" param
Since the parameter is already non-primitive, make it an `opts` map
instead of just a list, in case we want to extend it later.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5480bb5173..ab67bc2a3e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1418,32 +1418,52 @@ Dictionary nvim_get_color_map(void) /// Gets a map of the current editor state. /// -/// @param types Context types ("regs", "jumps", "buflist", "gvars", ...) -/// to gather, or NIL for all (see |context-types|). +/// @param opts Optional parameters. +/// - types: List of |context-types| ("regs", "jumps", "buflist", +/// "gvars", …) to gather, or empty for "all". +/// @param[out] err Error details, if any /// /// @return map of global |context|. -Dictionary nvim_get_context(Array types) +Dictionary nvim_get_context(Dictionary opts, Error *err) FUNC_API_SINCE(6) { - int int_types = 0; - if (types.size == 1 && types.items[0].type == kObjectTypeNil) { - int_types = kCtxAll; - } else { + Array types = ARRAY_DICT_INIT; + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object v = opts.items[i].value; + if (strequal("types", k.data)) { + if (v.type != kObjectTypeArray) { + api_set_error(err, kErrorTypeValidation, "invalid value for key: %s", + k.data); + return (Dictionary)ARRAY_DICT_INIT; + } + types = v.data.array; + } else { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + return (Dictionary)ARRAY_DICT_INIT; + } + } + + int int_types = types.size > 0 ? 0 : kCtxAll; + if (types.size > 0) { for (size_t i = 0; i < types.size; i++) { if (types.items[i].type == kObjectTypeString) { - const char *const current = types.items[i].data.string.data; - if (strequal(current, "regs")) { + const char *const s = types.items[i].data.string.data; + if (strequal(s, "regs")) { int_types |= kCtxRegs; - } else if (strequal(current, "jumps")) { + } else if (strequal(s, "jumps")) { int_types |= kCtxJumps; - } else if (strequal(current, "buflist")) { + } else if (strequal(s, "buflist")) { int_types |= kCtxBuflist; - } else if (strequal(current, "gvars")) { + } else if (strequal(s, "gvars")) { int_types |= kCtxGVars; - } else if (strequal(current, "sfuncs")) { + } else if (strequal(s, "sfuncs")) { int_types |= kCtxSFuncs; - } else if (strequal(current, "funcs")) { + } else if (strequal(s, "funcs")) { int_types |= kCtxFuncs; + } else { + api_set_error(err, kErrorTypeValidation, "unexpected type: %s", s); + return (Dictionary)ARRAY_DICT_INIT; } } } |