mirror of
https://github.com/neovim/neovim.git
synced 2026-05-23 21:30:11 +00:00
feat(api): nvim_get_commands returns desc #39623
Problem: Can't get a command's description from nvim_get_commands when cmd is string. Solution: Returns "desc" field in nvim_get_commands. `definition` is now empty when cmd is function type.
This commit is contained in:
@@ -23,6 +23,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = 'echo "Hello World"',
|
||||
desc = '',
|
||||
name = 'Hello',
|
||||
nargs = '1',
|
||||
range = NIL,
|
||||
@@ -38,6 +39,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = 'pwd',
|
||||
desc = '',
|
||||
name = 'Pwd',
|
||||
nargs = '?',
|
||||
range = NIL,
|
||||
@@ -54,6 +56,15 @@ describe('nvim_get_commands', function()
|
||||
it('validation', function()
|
||||
eq('builtin=true not implemented', pcall_err(api.nvim_get_commands, { builtin = true }))
|
||||
eq("Invalid key: 'foo'", pcall_err(api.nvim_get_commands, { foo = 'blah' }))
|
||||
matches(
|
||||
"Invalid 'desc'",
|
||||
pcall_err(
|
||||
exec_lua,
|
||||
[[
|
||||
vim.api.nvim_create_user_command('Bad', 'echo "hi"', { desc = 123 })
|
||||
]]
|
||||
)
|
||||
)
|
||||
end)
|
||||
|
||||
it('gets global user-defined commands', function()
|
||||
@@ -92,6 +103,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = '10',
|
||||
definition = 'pwd <args>',
|
||||
desc = '',
|
||||
name = 'TestCmd',
|
||||
nargs = '1',
|
||||
range = '10',
|
||||
@@ -107,6 +119,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = 'ListUsers',
|
||||
count = NIL,
|
||||
definition = '!finger <args>',
|
||||
desc = '',
|
||||
name = 'Finger',
|
||||
nargs = '+',
|
||||
range = NIL,
|
||||
@@ -122,6 +135,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = 'call \128\253R2_foo(<q-args>)',
|
||||
desc = '',
|
||||
name = 'Cmd2',
|
||||
nargs = '*',
|
||||
range = NIL,
|
||||
@@ -137,6 +151,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = 'call \128\253R3_ohyeah()',
|
||||
desc = '',
|
||||
name = 'Cmd3',
|
||||
nargs = '0',
|
||||
range = NIL,
|
||||
@@ -152,6 +167,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = 'call \128\253R4_just_great()',
|
||||
desc = '',
|
||||
name = 'Cmd4',
|
||||
nargs = '0',
|
||||
range = NIL,
|
||||
@@ -167,6 +183,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = 's:cpt',
|
||||
count = NIL,
|
||||
definition = '',
|
||||
desc = '',
|
||||
name = 'PreviewCmd',
|
||||
nargs = '1',
|
||||
range = NIL,
|
||||
@@ -184,6 +201,7 @@ describe('nvim_get_commands', function()
|
||||
complete_arg = NIL,
|
||||
count = NIL,
|
||||
definition = '',
|
||||
desc = 'Preview Lua Cmd',
|
||||
name = 'PreviewLuaCmd',
|
||||
nargs = '1',
|
||||
range = NIL,
|
||||
@@ -191,6 +209,22 @@ describe('nvim_get_commands', function()
|
||||
keepscript = false,
|
||||
script_id = -8, -- Lua
|
||||
}
|
||||
local withDesc = {
|
||||
addr = vim.NIL,
|
||||
bang = false,
|
||||
bar = false,
|
||||
complete = vim.NIL,
|
||||
complete_arg = vim.NIL,
|
||||
count = vim.NIL,
|
||||
definition = 'echo "hi"',
|
||||
desc = 'Says hi',
|
||||
keepscript = false,
|
||||
name = 'WithDesc',
|
||||
nargs = '0',
|
||||
range = vim.NIL,
|
||||
register = false,
|
||||
script_id = -8,
|
||||
}
|
||||
|
||||
source([[
|
||||
let s:foo = 1
|
||||
@@ -230,8 +264,14 @@ describe('nvim_get_commands', function()
|
||||
nargs = 1,
|
||||
complete = function() return 3 end,
|
||||
preview = function() return 4 end,
|
||||
desc = 'Preview Lua Cmd'
|
||||
}
|
||||
)
|
||||
vim.api.nvim_create_user_command(
|
||||
'WithDesc',
|
||||
'echo "hi"',
|
||||
{ desc = 'Says hi' }
|
||||
)
|
||||
EOF
|
||||
]])
|
||||
-- TODO(justinmk): Order is stable but undefined. Sort before return?
|
||||
@@ -244,6 +284,7 @@ describe('nvim_get_commands', function()
|
||||
TestCmd = cmd0,
|
||||
PreviewCmd = previewCmd,
|
||||
PreviewLuaCmd = previewLuaCmd,
|
||||
WithDesc = withDesc,
|
||||
}, commands)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user