diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-14 19:53:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-14 19:53:33 -0700 |
commit | 86e819d492faa2494ffe0e86f37c49eb4c0f2e56 (patch) | |
tree | 63a0fde18014ec2be04cadc81486cf7fe5243ef6 /src/nvim/api/vim.c | |
parent | 2e0e592ea29ea7d2da333824a93aa543a6f7f390 (diff) | |
parent | ffdf8c4c1227874a62b950cc7138005b40004c6a (diff) | |
download | rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.tar.gz rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.tar.bz2 rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.zip |
Merge #11021 from justinmk/ctx-rename-buflist
API: Context: "opts" param, et al.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5480bb5173..602733fd31 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", "bufs", +/// "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")) { - int_types |= kCtxBuflist; - } else if (strequal(current, "gvars")) { + } else if (strequal(s, "bufs")) { + int_types |= kCtxBufs; + } 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; } } } |