aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-05-10 23:37:56 +0200
committerJustin M. Keyes <justinkz@gmail.com>2018-05-11 13:20:43 +0200
commit9fa7727ce047e8e2e13f9fbf60d5defe9cf45060 (patch)
tree004351a01979a8c680a47243705dfc1df782fb06 /src/nvim/api
parent25b630484023716977c3fe2790c13b41f9db9f30 (diff)
downloadrneovim-9fa7727ce047e8e2e13f9fbf60d5defe9cf45060.tar.gz
rneovim-9fa7727ce047e8e2e13f9fbf60d5defe9cf45060.tar.bz2
rneovim-9fa7727ce047e8e2e13f9fbf60d5defe9cf45060.zip
API: nvim_get_commands(): always return keys
- Always return all keys, with at least NIL value. - Require `opts` param to be {"builtin":false} - Validate `opts` param
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/buffer.c28
-rw-r--r--src/nvim/api/private/helpers.c16
-rw-r--r--src/nvim/api/vim.c8
3 files changed, 35 insertions, 17 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index c4508a0c81..878c8aad87 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -479,12 +479,11 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
return keymap_array(mode, buf);
}
-/// Gets a list of dictionaries describing buffer-local commands.
-/// The "buffer" key in the returned dictionary reflects the buffer
-/// handle where the command is present.
+/// Gets a list of maps describing buffer-local |user-commands|.
///
-/// @param buffer Buffer handle.
-/// @param opts Optional parameters, currently always
+/// @param buffer Buffer handle.
+/// @param opts Optional parameters. Currently only supports
+/// {"builtin":false}
/// @param[out] err Error details, if any.
///
/// @returns Array of dictionaries describing commands.
@@ -492,6 +491,25 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts,
Error *err)
FUNC_API_SINCE(4)
{
+ for (size_t i = 0; i < opts.size; i++) {
+ String k = opts.items[i].key;
+ Object v = opts.items[i].value;
+ if (!strequal("builtin", k.data)) {
+ api_set_error(err, kErrorTypeValidation, "unexpected key: %s",
+ k.data);
+ return (Array)ARRAY_DICT_INIT;
+ }
+ if (v.type != kObjectTypeBoolean || v.data.boolean != false) {
+ api_set_error(err, kErrorTypeValidation,
+ "builtin commands not supported yet");
+ return (Array)ARRAY_DICT_INIT;
+ }
+ }
+
+ if (buffer == -1) {
+ return commands_array(NULL);
+ }
+
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return (Array)ARRAY_DICT_INIT;
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 03f1a882d3..17ee3ed711 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -685,7 +685,7 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err)
String cchar_to_string(char c)
{
char buf[] = { c, NUL };
- return (String) {
+ return (String){
.data = xmemdupz(buf, 1),
.size = (c != NUL) ? 1 : 0
};
@@ -701,13 +701,13 @@ String cchar_to_string(char c)
String cstr_to_string(const char *str)
{
if (str == NULL) {
- return (String) STRING_INIT;
+ return (String)STRING_INIT;
}
size_t len = strlen(str);
- return (String) {
- .data = xmemdupz(str, len),
- .size = len
+ return (String){
+ .data = xmemdupz(str, len),
+ .size = len,
};
}
@@ -722,7 +722,7 @@ String cstr_to_string(const char *str)
String cbuf_to_string(const char *buf, size_t size)
FUNC_ATTR_NONNULL_ALL
{
- return (String) {
+ return (String){
.data = xmemdupz(buf, size),
.size = size
};
@@ -737,9 +737,9 @@ String cbuf_to_string(const char *buf, size_t size)
String cstr_as_string(char *str) FUNC_ATTR_PURE
{
if (str == NULL) {
- return (String) STRING_INIT;
+ return (String)STRING_INIT;
}
- return (String) { .data = str, .size = strlen(str) };
+ return (String){ .data = str, .size = strlen(str) };
}
/// Converts from type Object to a VimL value.
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 38e64fd6ed..065b8d1ce2 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -959,17 +959,17 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode)
return keymap_array(mode, NULL);
}
-/// Gets a list of dictionaries describing global(non-buffer) commands.
+/// Gets a list of maps describing global |user-commands|.
///
-/// @param opts Holds the API Metadata describing what type of commands
-/// are needed.
+/// @param opts Optional parameters. Currently only supports
+/// {"builtin":false}
/// @param[out] err Error details, if any.
///
/// @returns Array of dictionaries describing commands.
ArrayOf(Dictionary) nvim_get_commands(Dictionary opts, Error *err)
FUNC_API_SINCE(4)
{
- return commands_array(NULL);
+ return nvim_buf_get_commands(-1, opts, err);
}
/// Returns a 2-tuple (Array), where item 0 is the current channel id and item