From 8bf79bd13c4d37a96109c8a6a924acb59d8e8ae5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 12 Jun 2024 15:35:54 +0100 Subject: fix(vim.wo): never allow non-zero bufnr --- runtime/lua/vim/_options.lua | 11 +++++------ test/functional/lua/vim_spec.lua | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/runtime/lua/vim/_options.lua b/runtime/lua/vim/_options.lua index 4a360c18e4..a61fa61256 100644 --- a/runtime/lua/vim/_options.lua +++ b/runtime/lua/vim/_options.lua @@ -174,6 +174,11 @@ local function new_buf_opt_accessor(bufnr) end local function new_win_opt_accessor(winid, bufnr) + -- TODO(lewis6991): allow passing both buf and win to nvim_get_option_value + if bufnr ~= nil and bufnr ~= 0 then + error('only bufnr=0 is supported') + end + return setmetatable({}, { __index = function(_, k) if bufnr == nil and type(k) == 'number' then @@ -184,11 +189,6 @@ local function new_win_opt_accessor(winid, bufnr) end end - if bufnr ~= nil and bufnr ~= 0 then - error('only bufnr=0 is supported') - end - - -- TODO(lewis6991): allow passing both buf and win to nvim_get_option_value return api.nvim_get_option_value(k, { scope = bufnr and 'local' or nil, win = winid or 0, @@ -196,7 +196,6 @@ local function new_win_opt_accessor(winid, bufnr) end, __newindex = function(_, k, v) - -- TODO(lewis6991): allow passing both buf and win to nvim_set_option_value return api.nvim_set_option_value(k, v, { scope = bufnr and 'local' or nil, win = winid or 0, diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index d50b646085..0814f42545 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2023,6 +2023,16 @@ describe('lua stdlib', function() vim.cmd "enew" ]] eq(100, fn.luaeval 'vim.wo.scrolloff') + + matches( + 'only bufnr=0 is supported', + pcall_err(exec_lua, 'vim.wo[0][10].signcolumn = "no"') + ) + + matches( + 'only bufnr=0 is supported', + pcall_err(exec_lua, 'local a = vim.wo[0][10].signcolumn') + ) end) describe('vim.opt', function() -- cgit From 2ca678f57de1cb4332d39337ae1c5a63a1ff434a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 12 Jun 2024 15:47:42 +0100 Subject: test: fix vim.deprecate tests --- test/functional/lua/vim_spec.lua | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 0814f42545..23bb9f0a2e 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -135,14 +135,15 @@ describe('lua stdlib', function() -- See MAINTAIN.md for the soft/hard deprecation policy describe(('vim.deprecate prerel=%s,'):format(prerel or 'nil'), function() - local curver = exec_lua('return vim.version()') --[[@as {major:number, minor:number}]] - -- "0.10" or "0.10-dev+xxx" - local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') - -- "0.10" or "0.11" - local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1)) - local was_removed = prerel and 'was removed' or 'will be removed' + local curver --- @type {major:number, minor:number} + + before_each(function() + curver = exec_lua('return vim.version()') + end) it('plugin=nil, same message skipped', function() + -- "0.10" or "0.10-dev+xxx" + local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') eq( dedent( [[ @@ -162,6 +163,10 @@ describe('lua stdlib', function() end) it('plugin=nil, show error if hard-deprecated', function() + -- "0.10" or "0.11" + local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1)) + + local was_removed = prerel and 'was removed' or 'will be removed' eq( dedent( [[ @@ -2024,15 +2029,9 @@ describe('lua stdlib', function() ]] eq(100, fn.luaeval 'vim.wo.scrolloff') - matches( - 'only bufnr=0 is supported', - pcall_err(exec_lua, 'vim.wo[0][10].signcolumn = "no"') - ) + matches('only bufnr=0 is supported', pcall_err(exec_lua, 'vim.wo[0][10].signcolumn = "no"')) - matches( - 'only bufnr=0 is supported', - pcall_err(exec_lua, 'local a = vim.wo[0][10].signcolumn') - ) + matches('only bufnr=0 is supported', pcall_err(exec_lua, 'local a = vim.wo[0][10].signcolumn')) end) describe('vim.opt', function() -- cgit