fix(vim.opt): Get window options before setting.

This closes #14677, but I also am a little unsure if there are times
where this may not be correct. However, this just changes the behavior
that even if `was_set` was false, we still get for
`nvim_win_get_option`.
This commit is contained in:
ckipp01
2021-05-30 13:08:43 +02:00
committed by TJ DeVries
parent 1d3ee1c441
commit e6175f6389
2 changed files with 24 additions and 4 deletions

View File

@@ -209,12 +209,17 @@ local function get_scoped_option(k, set_type)
end end
if is_window_option(info) then if is_window_option(info) then
if vim.api.nvim_get_option_info(k).was_set then local ok, value = pcall(a.nvim_win_get_option, 0, k)
local was_set, value = pcall(a.nvim_win_get_option, 0, k) if ok then
if was_set then return value end return value
end end
return a.nvim_get_option(k) local global_ok, global_val = pcall(a.nvim_get_option, k)
if global_ok then
return global_val
end
error("win_get: This should never happen. File an issue and tag @tjdevries")
end end
error("This fallback case should not be possible. " .. k) error("This fallback case should not be possible. " .. k)

View File

@@ -1228,6 +1228,21 @@ describe('lua stdlib', function()
eq("only-local", result[8]) eq("only-local", result[8])
end) end)
it('should allow you to retrieve window opts even if they have not been set', function()
local result = exec_lua [[
local result = {}
table.insert(result, vim.opt.number:get())
table.insert(result, vim.opt_local.number:get())
vim.opt_local.number = true
table.insert(result, vim.opt.number:get())
table.insert(result, vim.opt_local.number:get())
return result
]]
eq({false, false, true, true}, result)
end)
it('should allow all sorts of string manipulation', function() it('should allow all sorts of string manipulation', function()
eq({'hello', 'hello world', 'start hello world'}, exec_lua [[ eq({'hello', 'hello world', 'start hello world'}, exec_lua [[
local results = {} local results = {}