mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18864 from bfredl/optcut
perf(tests): don't invoke nvim_get_all_options_info until needed
This commit is contained in:
commit
e13dcdf162
@ -10,28 +10,38 @@ local SET_TYPES = setmetatable({
|
|||||||
GLOBAL = 2,
|
GLOBAL = 2,
|
||||||
}, { __index = error })
|
}, { __index = error })
|
||||||
|
|
||||||
local options_info = {}
|
local options_info = nil
|
||||||
for _, v in pairs(a.nvim_get_all_options_info()) do
|
local buf_options = nil
|
||||||
options_info[v.name] = v
|
local glb_options = nil
|
||||||
if v.shortname ~= '' then
|
local win_options = nil
|
||||||
options_info[v.shortname] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local get_scoped_options = function(scope)
|
local function _setup()
|
||||||
local result = {}
|
if options_info ~= nil then
|
||||||
for name, option_info in pairs(options_info) do
|
return
|
||||||
if option_info.scope == scope then
|
end
|
||||||
result[name] = true
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
local function get_scoped_options(scope)
|
||||||
end
|
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')
|
return result
|
||||||
local glb_options = get_scoped_options('global')
|
end
|
||||||
local win_options = get_scoped_options('win')
|
|
||||||
|
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)
|
local function make_meta_accessor(get, set, del, validator)
|
||||||
validator = validator or function()
|
validator = validator or function()
|
||||||
@ -90,6 +100,7 @@ do -- buffer option accessor
|
|||||||
|
|
||||||
return make_meta_accessor(get, set, nil, function(k)
|
return make_meta_accessor(get, set, nil, function(k)
|
||||||
if type(k) == 'string' then
|
if type(k) == 'string' then
|
||||||
|
_setup()
|
||||||
if win_options[k] then
|
if win_options[k] then
|
||||||
error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k))
|
error(string.format([['%s' is a window option, not a buffer option. See ":help %s"]], k, k))
|
||||||
elseif glb_options[k] then
|
elseif glb_options[k] then
|
||||||
@ -119,6 +130,7 @@ do -- window option accessor
|
|||||||
|
|
||||||
return make_meta_accessor(get, set, nil, function(k)
|
return make_meta_accessor(get, set, nil, function(k)
|
||||||
if type(k) == 'string' then
|
if type(k) == 'string' then
|
||||||
|
_setup()
|
||||||
if buf_options[k] then
|
if buf_options[k] then
|
||||||
error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k))
|
error(string.format([['%s' is a buffer option, not a window option. See ":help %s"]], k, k))
|
||||||
elseif glb_options[k] then
|
elseif glb_options[k] then
|
||||||
@ -610,6 +622,7 @@ local create_option_metatable = function(set_type)
|
|||||||
local set_mt, option_mt
|
local set_mt, option_mt
|
||||||
|
|
||||||
local make_option = function(name, value)
|
local make_option = function(name, value)
|
||||||
|
_setup()
|
||||||
local info = assert(options_info[name], 'Not a valid option name: ' .. name)
|
local info = assert(options_info[name], 'Not a valid option name: ' .. name)
|
||||||
|
|
||||||
if type(value) == 'table' and getmetatable(value) == option_mt then
|
if type(value) == 'table' and getmetatable(value) == option_mt then
|
||||||
|
Loading…
Reference in New Issue
Block a user