mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
API: nvim_get_commands(): builtin is irrelevant for buffer-local
builtin commands are never buffer-local, so we can return empty for that case.
This commit is contained in:
@@ -481,8 +481,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
|
|||||||
/// Gets a list of buffer-local |user-commands|.
|
/// Gets a list of buffer-local |user-commands|.
|
||||||
///
|
///
|
||||||
/// @param buffer Buffer handle.
|
/// @param buffer Buffer handle.
|
||||||
/// @param opts Optional parameters. Currently only supports
|
/// @param opts Optional parameters. Currently not used.
|
||||||
/// {"builtin":false}
|
|
||||||
/// @param[out] err Error details, if any.
|
/// @param[out] err Error details, if any.
|
||||||
///
|
///
|
||||||
/// @returns Array of dictionaries describing commands.
|
/// @returns Array of dictionaries describing commands.
|
||||||
@@ -490,27 +489,31 @@ ArrayOf(Dictionary) nvim_buf_get_commands(Buffer buffer, Dictionary opts,
|
|||||||
Error *err)
|
Error *err)
|
||||||
FUNC_API_SINCE(4)
|
FUNC_API_SINCE(4)
|
||||||
{
|
{
|
||||||
|
bool global = (buffer == -1);
|
||||||
|
bool builtin = false;
|
||||||
|
|
||||||
for (size_t i = 0; i < opts.size; i++) {
|
for (size_t i = 0; i < opts.size; i++) {
|
||||||
String k = opts.items[i].key;
|
String k = opts.items[i].key;
|
||||||
Object v = opts.items[i].value;
|
Object v = opts.items[i].value;
|
||||||
if (!strequal("builtin", k.data)) {
|
if (!strequal("builtin", k.data)) {
|
||||||
api_set_error(err, kErrorTypeValidation, "unexpected key: %s",
|
api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);
|
||||||
k.data);
|
|
||||||
return (Array)ARRAY_DICT_INIT;
|
return (Array)ARRAY_DICT_INIT;
|
||||||
}
|
}
|
||||||
if (v.type != kObjectTypeBoolean || v.data.boolean != false) {
|
if (strequal("builtin", k.data)) {
|
||||||
api_set_error(err, kErrorTypeValidation,
|
builtin = v.data.boolean;
|
||||||
"builtin commands not supported yet");
|
|
||||||
return (Array)ARRAY_DICT_INIT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
return commands_array(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
if (!buf) {
|
if (builtin || !buf) {
|
||||||
return (Array)ARRAY_DICT_INIT;
|
return (Array)ARRAY_DICT_INIT;
|
||||||
}
|
}
|
||||||
return commands_array(buf);
|
return commands_array(buf);
|
||||||
|
@@ -19,7 +19,7 @@ describe('nvim_get_commands', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('validates input', function()
|
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})
|
{builtin=true})
|
||||||
expect_err('unexpected key: foo', meths.get_commands,
|
expect_err('unexpected key: foo', meths.get_commands,
|
||||||
{foo='blah'})
|
{foo='blah'})
|
||||||
@@ -47,6 +47,9 @@ describe('nvim_get_commands', function()
|
|||||||
-- Delete a command.
|
-- Delete a command.
|
||||||
command('delcommand Pwd')
|
command('delcommand Pwd')
|
||||||
eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
||||||
|
|
||||||
|
-- {builtin=true} always returns empty for buffer-local case.
|
||||||
|
eq({}, curbufmeths.get_commands({builtin=true}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('gets various command attributes', function()
|
it('gets various command attributes', function()
|
||||||
|
Reference in New Issue
Block a user