mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(lua): preserve argument lists which are not lists
This commit is contained in:
parent
636ecd0c3b
commit
6896d22b63
@ -27,5 +27,14 @@ function F.nil_wrap(fn)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- like {...} except preserve the lenght explicitly
|
||||||
|
function F.pack_len(...)
|
||||||
|
return {n=select('#', ...), ...}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- like unpack() but use the length set by F.pack_len if present
|
||||||
|
function F.unpack_len(t)
|
||||||
|
return unpack(t, 1, t.n)
|
||||||
|
end
|
||||||
|
|
||||||
return F
|
return F
|
||||||
|
@ -273,8 +273,8 @@ end
|
|||||||
---@see |vim.in_fast_event()|
|
---@see |vim.in_fast_event()|
|
||||||
function vim.schedule_wrap(cb)
|
function vim.schedule_wrap(cb)
|
||||||
return (function (...)
|
return (function (...)
|
||||||
local args = {...}
|
local args = vim.F.pack_len(...)
|
||||||
vim.schedule(function() cb(unpack(args)) end)
|
vim.schedule(function() cb(vim.F.unpack_len(args)) end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ local matches = helpers.matches
|
|||||||
local source = helpers.source
|
local source = helpers.source
|
||||||
local NIL = helpers.NIL
|
local NIL = helpers.NIL
|
||||||
local retry = helpers.retry
|
local retry = helpers.retry
|
||||||
|
local next_msg = helpers.next_msg
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@ -2178,6 +2179,24 @@ describe('lua stdlib', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('vim.schedule_wrap', function()
|
||||||
|
it('preserves argument lists', function()
|
||||||
|
exec_lua [[
|
||||||
|
local fun = vim.schedule_wrap(function(kling, klang, klonk)
|
||||||
|
vim.rpcnotify(1, 'mayday_mayday', {a=kling, b=klang, c=klonk})
|
||||||
|
end)
|
||||||
|
fun("BOB", nil, "MIKE")
|
||||||
|
]]
|
||||||
|
eq({'notification', 'mayday_mayday', {{a='BOB', c='MIKE'}}}, next_msg())
|
||||||
|
|
||||||
|
-- let's gooooo
|
||||||
|
exec_lua [[
|
||||||
|
vim.schedule_wrap(function(...) vim.rpcnotify(1, 'boogalo', select('#', ...)) end)(nil,nil,nil,nil)
|
||||||
|
]]
|
||||||
|
eq({'notification', 'boogalo', {4}}, next_msg())
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('vim.api.nvim_buf_call', function()
|
describe('vim.api.nvim_buf_call', function()
|
||||||
it('can access buf options', function()
|
it('can access buf options', function()
|
||||||
local buf1 = meths.get_current_buf()
|
local buf1 = meths.get_current_buf()
|
||||||
|
Loading…
Reference in New Issue
Block a user