From 3a5b46e6bb92390b814198098f0ed5318bc21614 Mon Sep 17 00:00:00 2001 From: Phelipe Teles <39670535+phelipetls@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:35:12 -0300 Subject: [PATCH] fix(lua): not using global value in vim.opt_global --- runtime/lua/vim/_options.lua | 5 ++++- test/functional/lua/vim_spec.lua | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/lua/vim/_options.lua b/runtime/lua/vim/_options.lua index e3ad4d76c9..f42f3ef1ca 100644 --- a/runtime/lua/vim/_options.lua +++ b/runtime/lua/vim/_options.lua @@ -526,7 +526,10 @@ local function create_option_accessor(scope) return setmetatable({}, { __index = function(_, k) - return make_option(k, api.nvim_get_option_value(k, {})) + -- vim.opt_global must get global value only + -- vim.opt_local may fall back to global value like vim.opt + local opts = { scope = scope == 'global' and 'global' or nil } + return make_option(k, api.nvim_get_option_value(k, opts)) end, __newindex = function(_, k, v) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 928dda68ed..3b581c608f 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2222,8 +2222,8 @@ describe('lua stdlib', function() end) end) -- vim.opt - describe('opt_local', function() - it('should be able to append to an array list type option', function() + describe('vim.opt_local', function() + it('appends into global value when changing local option value', function() eq({ "foo,bar,baz,qux" }, exec_lua [[ local result = {} @@ -2238,6 +2238,19 @@ describe('lua stdlib', function() end) end) + describe('vim.opt_global', function() + it('gets current global option value', function() + eq({ "yes" }, exec_lua [[ + local result = {} + + vim.cmd "setglobal signcolumn=yes" + table.insert(result, vim.opt_global.signcolumn:get()) + + return result + ]]) + end) + end) + it('vim.cmd', function() exec_lua [[ vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('')"