mirror of
https://github.com/neovim/neovim.git
synced 2026-05-26 14:58:28 +00:00
fix(api): regressions with lua return values #39837
fixes #39834 fixes #39833 fixes #39851
This commit is contained in:
@@ -188,7 +188,7 @@ describe('api/buf', function()
|
||||
eq(0, api.nvim_buf_line_count(bufnr))
|
||||
end)
|
||||
|
||||
it('get_lines has defined behaviour for unloaded buffers', function()
|
||||
it('get_lines and get_text has defined behaviour for unloaded buffers', function()
|
||||
-- we'll need to know our bufnr for when it gets unloaded
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
-- replace the buffer contents with these three lines
|
||||
@@ -202,6 +202,22 @@ describe('api/buf', function()
|
||||
eq({}, api.nvim_buf_get_lines(bufnr, 1, 3, true))
|
||||
-- it's impossible to get out-of-bounds errors for an unloaded buffer
|
||||
eq({}, api.nvim_buf_get_lines(bufnr, 8888, 9999, true))
|
||||
eq({}, api.nvim_buf_get_text(bufnr, 8888, 1000, 9999, 2000, {}))
|
||||
-- The Lua path (vim.api) must also return an empty table, not nil. #39833 #39851
|
||||
eq(
|
||||
{ 'table', {} },
|
||||
exec_lua(function()
|
||||
local r = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
return { type(r), r }
|
||||
end)
|
||||
)
|
||||
eq(
|
||||
{ 'table', {} },
|
||||
exec_lua(function()
|
||||
local r = vim.api.nvim_buf_get_text(bufnr, 0, 0, -1, 0, {})
|
||||
return { type(r), r }
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
describe('handles topline', function()
|
||||
@@ -2498,6 +2514,32 @@ describe('api/buf', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('propagates return values when called from a coroutine #39834', function()
|
||||
local other = api.nvim_create_buf(false, true)
|
||||
eq(
|
||||
{ other, vim.NIL, 42 },
|
||||
exec_lua(function()
|
||||
local out
|
||||
local co = coroutine.create(function()
|
||||
local function pack(...)
|
||||
local r = { ... }
|
||||
for i = 1, select('#', ...) do
|
||||
if r[i] == nil then
|
||||
r[i] = vim.NIL
|
||||
end
|
||||
end
|
||||
return r
|
||||
end
|
||||
out = pack(vim.api.nvim_buf_call(other, function()
|
||||
return vim.api.nvim_get_current_buf(), nil, 42
|
||||
end))
|
||||
end)
|
||||
assert(coroutine.resume(co))
|
||||
return out
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('can access buf options', function()
|
||||
local buf1 = api.nvim_get_current_buf()
|
||||
local buf2 = exec_lua [[
|
||||
|
||||
Reference in New Issue
Block a user