Merge pull request #18864 from bfredl/optcut

perf(tests): don't invoke nvim_get_all_options_info until needed
This commit is contained in:
bfredl 2022-06-05 00:48:43 +02:00 committed by GitHub
commit e13dcdf162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,28 +10,38 @@ local SET_TYPES = setmetatable({
GLOBAL = 2,
}, { __index = error })
local options_info = {}
for _, v in pairs(a.nvim_get_all_options_info()) do
options_info[v.name] = v
if v.shortname ~= '' then
options_info[v.shortname] = v
end
end
local options_info = nil
local buf_options = nil
local glb_options = nil
local win_options = nil
local get_scoped_options = function(scope)
local result = {}
for name, option_info in pairs(options_info) do
if option_info.scope == scope then
result[name] = true
local function _setup()
if options_info ~= nil then
return
end
options_info = {}
for _, v in pairs(a.nvim_get_all_options_info()) do
options_info[v.name] = v
if v.shortname ~= '' then
options_info[v.shortname] = v
end
end
return result
end
local function get_scoped_options(scope)
local result = {}
for name, option_info in pairs(options_info) do
if option_info.scope == scope then
result[name] = true
end
end
local buf_options = get_scoped_options('buf')
local glb_options = get_scoped_options('global')
local win_options = get_scoped_options('win')
return result
end
buf_options = get_scoped_options('buf')
glb_options = get_scoped_options('global')
win_options = get_scoped_options('win')
end
local function make_meta_accessor(get, set, del, validator)
validator = validator or function()
@ -90,6 +100,7 @@ do -- buffer option accessor
return make_meta_accessor(get, set, nil, function(k)
if type(k) == 'string' then
_setup()
if win_options[k] then
error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k))
elseif glb_options[k] then
@ -119,6 +130,7 @@ do -- window option accessor
return make_meta_accessor(get, set, nil, function(k)
if type(k) == 'string' then
_setup()
if buf_options[k] then
error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k))
elseif glb_options[k] then
@ -610,6 +622,7 @@ local create_option_metatable = function(set_type)
local set_mt, option_mt
local make_option = function(name, value)
_setup()
local info = assert(options_info[name], 'Not a valid option name: ' .. name)
if type(value) == 'table' and getmetatable(value) == option_mt then