aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/buffer.c23
-rw-r--r--test/functional/api/command_spec.lua5
2 files changed, 17 insertions, 11 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 19f92f002d..eda7fcd74c 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -481,8 +481,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
/// Gets a list of buffer-local |user-commands|.
///
/// @param buffer Buffer handle.
-/// @param opts Optional parameters. Currently only supports
-/// {"builtin":false}
+/// @param opts Optional parameters. Currently not used.
/// @param[out] err Error details, if any.
///
/// @returns Array of dictionaries describing commands.
@@ -490,27 +489,31 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts,
Error *err)
FUNC_API_SINCE(4)
{
+ bool global = (buffer == -1);
+ bool builtin = false;
+
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);
+ 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 (strequal("builtin", k.data)) {
+ builtin = v.data.boolean;
}
}
- if (buffer == -1) {
+ if (global) {
+ if (builtin) {
+ api_set_error(err, kErrorTypeValidation, "builtin=true not implemented");
+ return (Array)ARRAY_DICT_INIT;
+ }
return commands_array(NULL);
}
buf_T *buf = find_buffer_by_handle(buffer, err);
- if (!buf) {
+ if (builtin || !buf) {
return (Array)ARRAY_DICT_INIT;
}
return commands_array(buf);
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index 149a5dd111..c7cf081355 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -19,7 +19,7 @@ describe('nvim_get_commands', function()
end)
it('validates input', function()
- expect_err('builtin commands not supported yet', meths.get_commands,
+ expect_err('builtin=true not implemented', meths.get_commands,
{builtin=true})
expect_err('unexpected key: foo', meths.get_commands,
{foo='blah'})
@@ -47,6 +47,9 @@ describe('nvim_get_commands', function()
-- Delete a command.
command('delcommand Pwd')
eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
+
+ -- {builtin=true} always returns empty for buffer-local case.
+ eq({}, curbufmeths.get_commands({builtin=true}))
end)
it('gets various command attributes', function()