mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
API: nvim_get_commands(): more attributes
Support more :command attributes: -bang -bar -register
This commit is contained in:
@@ -459,14 +459,13 @@ Integer nvim_buf_get_changedtick(Buffer buffer, Error *err)
|
|||||||
return buf->b_changedtick;
|
return buf->b_changedtick;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of dictionaries describing buffer-local mappings.
|
/// Gets a list of buffer-local |mapping| definitions.
|
||||||
/// The "buffer" key in the returned dictionary reflects the buffer
|
|
||||||
/// handle where the mapping is present.
|
|
||||||
///
|
///
|
||||||
/// @param mode Mode short-name ("n", "i", "v", ...)
|
/// @param mode Mode short-name ("n", "i", "v", ...)
|
||||||
/// @param buffer Buffer handle
|
/// @param buffer Buffer handle
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
/// @returns Array of maparg()-like dictionaries describing mappings
|
/// @returns Array of maparg()-like dictionaries describing mappings.
|
||||||
|
/// The "buffer" key holds the associated buffer handle.
|
||||||
ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
|
ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
|
||||||
FUNC_API_SINCE(3)
|
FUNC_API_SINCE(3)
|
||||||
{
|
{
|
||||||
@@ -479,7 +478,7 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(Buffer buffer, String mode, Error *err)
|
|||||||
return keymap_array(mode, buf);
|
return keymap_array(mode, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of maps describing 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 only supports
|
||||||
|
@@ -948,18 +948,20 @@ Dictionary nvim_get_mode(void)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of dictionaries describing global (non-buffer) mappings.
|
/// Gets a list of global (non-buffer-local) |mapping| definitions.
|
||||||
/// The "buffer" key in the returned dictionary is always zero.
|
|
||||||
///
|
///
|
||||||
/// @param mode Mode short-name ("n", "i", "v", ...)
|
/// @param mode Mode short-name ("n", "i", "v", ...)
|
||||||
/// @returns Array of maparg()-like dictionaries describing mappings
|
/// @returns Array of maparg()-like dictionaries describing mappings.
|
||||||
|
/// The "buffer" key is always zero.
|
||||||
ArrayOf(Dictionary) nvim_get_keymap(String mode)
|
ArrayOf(Dictionary) nvim_get_keymap(String mode)
|
||||||
FUNC_API_SINCE(3)
|
FUNC_API_SINCE(3)
|
||||||
{
|
{
|
||||||
return keymap_array(mode, NULL);
|
return keymap_array(mode, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of maps describing global |user-commands|.
|
/// Gets a list of global (non-buffer-local) Ex commands.
|
||||||
|
///
|
||||||
|
/// Currently only |user-commands| are supported, not builtin Ex commands.
|
||||||
///
|
///
|
||||||
/// @param opts Optional parameters. Currently only supports
|
/// @param opts Optional parameters. Currently only supports
|
||||||
/// {"builtin":false}
|
/// {"builtin":false}
|
||||||
|
@@ -9990,8 +9990,10 @@ ArrayOf(Dictionary) commands_array(buf_T *buf)
|
|||||||
PUT(d, "name", STRING_OBJ(cstr_to_string((char *)cmd->uc_name)));
|
PUT(d, "name", STRING_OBJ(cstr_to_string((char *)cmd->uc_name)));
|
||||||
PUT(d, "definition", STRING_OBJ(cstr_to_string((char *)cmd->uc_rep)));
|
PUT(d, "definition", STRING_OBJ(cstr_to_string((char *)cmd->uc_rep)));
|
||||||
PUT(d, "script_id", INTEGER_OBJ(cmd->uc_scriptID));
|
PUT(d, "script_id", INTEGER_OBJ(cmd->uc_scriptID));
|
||||||
|
PUT(d, "bang", BOOLEAN_OBJ(!!(cmd->uc_argt & BANG)));
|
||||||
|
PUT(d, "bar", BOOLEAN_OBJ(!!(cmd->uc_argt & TRLBAR)));
|
||||||
|
PUT(d, "register", BOOLEAN_OBJ(!!(cmd->uc_argt & REGSTR)));
|
||||||
|
|
||||||
// "nargs" key
|
|
||||||
switch (cmd->uc_argt & (EXTRA|NOSPC|NEEDARG)) {
|
switch (cmd->uc_argt & (EXTRA|NOSPC|NEEDARG)) {
|
||||||
case 0: arg[0] = '0'; break;
|
case 0: arg[0] = '0'; break;
|
||||||
case(EXTRA): arg[0] = '*'; break;
|
case(EXTRA): arg[0] = '*'; break;
|
||||||
|
@@ -10,38 +10,21 @@ local meths = helpers.meths
|
|||||||
local source = helpers.source
|
local source = helpers.source
|
||||||
|
|
||||||
describe('nvim_get_commands', function()
|
describe('nvim_get_commands', function()
|
||||||
local cmd_dict = {
|
local cmd_dict = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='echo "Hello World"', name='Hello', nargs='1', range=NIL, register=false, script_id=0, }
|
||||||
addr=NIL,
|
local cmd_dict2 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='pwd', name='Pwd', nargs='?', range=NIL, register=false, script_id=0, }
|
||||||
complete=NIL,
|
|
||||||
complete_arg=NIL,
|
|
||||||
count=NIL,
|
|
||||||
definition='echo "Hello World"',
|
|
||||||
name='Hello',
|
|
||||||
nargs='1',
|
|
||||||
range=NIL,
|
|
||||||
script_id=0,
|
|
||||||
}
|
|
||||||
local cmd_dict2 = {
|
|
||||||
addr=NIL,
|
|
||||||
complete=NIL,
|
|
||||||
complete_arg=NIL,
|
|
||||||
count=NIL,
|
|
||||||
definition='pwd',
|
|
||||||
name='Pwd',
|
|
||||||
nargs='?',
|
|
||||||
range=NIL,
|
|
||||||
script_id=0,
|
|
||||||
}
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
it('gets empty list if no commands were defined', function()
|
it('gets empty list if no commands were defined', function()
|
||||||
eq({}, meths.get_commands({builtin=false}))
|
eq({}, meths.get_commands({builtin=false}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('validates input', function()
|
it('validates input', function()
|
||||||
expect_err('builtin commands not supported yet', meths.get_commands,
|
expect_err('builtin commands not supported yet', 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'})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('gets global user-defined commands', function()
|
it('gets global user-defined commands', function()
|
||||||
-- Define a command.
|
-- Define a command.
|
||||||
command('command -nargs=1 Hello echo "Hello World"')
|
command('command -nargs=1 Hello echo "Hello World"')
|
||||||
@@ -53,6 +36,7 @@ describe('nvim_get_commands', function()
|
|||||||
command('delcommand Pwd')
|
command('delcommand Pwd')
|
||||||
eq({cmd_dict}, meths.get_commands({builtin=false}))
|
eq({cmd_dict}, meths.get_commands({builtin=false}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('gets buffer-local user-defined commands', function()
|
it('gets buffer-local user-defined commands', function()
|
||||||
-- Define a buffer-local command.
|
-- Define a buffer-local command.
|
||||||
command('command -buffer -nargs=1 Hello echo "Hello World"')
|
command('command -buffer -nargs=1 Hello echo "Hello World"')
|
||||||
@@ -64,34 +48,30 @@ describe('nvim_get_commands', function()
|
|||||||
command('delcommand Pwd')
|
command('delcommand Pwd')
|
||||||
eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
eq({cmd_dict}, curbufmeths.get_commands({builtin=false}))
|
||||||
end)
|
end)
|
||||||
it('gets different attributes of different commands', function()
|
|
||||||
local cmd1 = {
|
it('gets various command attributes', function()
|
||||||
addr=NIL,
|
local cmd0 = { addr='arguments', bang=false, bar=false, complete='dir', complete_arg=NIL, count='10', definition='pwd <args>', name='TestCmd', nargs='0', range='10', register=false, script_id=0, }
|
||||||
complete='custom',
|
local cmd1 = { addr=NIL, bang=false, bar=false, complete='custom', complete_arg='ListUsers', count=NIL, definition='!finger <args>', name='Finger', nargs='+', range=NIL, register=false, script_id=1, }
|
||||||
complete_arg='ListUsers',
|
local cmd2 = { addr=NIL, bang=true, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q2_foo(<q-args>)', name='Cmd2', nargs='*', range=NIL, register=false, script_id=2, }
|
||||||
count=NIL,
|
local cmd3 = { addr=NIL, bang=false, bar=true, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q3_ohyeah()', name='Cmd3', nargs='0', range=NIL, register=false, script_id=3, }
|
||||||
definition='!finger <args>',
|
local cmd4 = { addr=NIL, bang=false, bar=false, complete=NIL, complete_arg=NIL, count=NIL, definition='call \128\253Q4_just_great()', name='Cmd4', nargs='0', range=NIL, register=true, script_id=4, }
|
||||||
name='Finger',
|
|
||||||
nargs='+',
|
|
||||||
range=NIL,
|
|
||||||
script_id=1,
|
|
||||||
}
|
|
||||||
local cmd2 = {
|
|
||||||
addr='arguments',
|
|
||||||
complete='dir',
|
|
||||||
complete_arg=NIL,
|
|
||||||
count='10',
|
|
||||||
definition='pwd <args>',
|
|
||||||
name='TestCmd',
|
|
||||||
nargs='0',
|
|
||||||
range='10',
|
|
||||||
script_id=0,
|
|
||||||
}
|
|
||||||
source([[
|
source([[
|
||||||
command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
|
command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
|
||||||
]])
|
]])
|
||||||
eq({cmd1}, meths.get_commands({builtin=false}))
|
eq({cmd1}, meths.get_commands({builtin=false}))
|
||||||
command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
|
command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
|
||||||
eq({cmd1, cmd2}, meths.get_commands({builtin=false}))
|
eq({cmd1, cmd0}, meths.get_commands({builtin=false}))
|
||||||
|
|
||||||
|
source([[
|
||||||
|
command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
|
||||||
|
]])
|
||||||
|
source([[
|
||||||
|
command -bar -nargs=0 Cmd3 call <SID>ohyeah()
|
||||||
|
]])
|
||||||
|
source([[
|
||||||
|
command -register Cmd4 call <SID>just_great()
|
||||||
|
]])
|
||||||
|
-- TODO(justinmk): Order is stable but undefined. Sort before return?
|
||||||
|
eq({cmd2, cmd3, cmd4, cmd1, cmd0}, meths.get_commands({builtin=false}))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user