aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_meta.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-06-05 00:48:43 +0200
committerGitHub <noreply@github.com>2022-06-05 00:48:43 +0200
commite13dcdf162d166084f19f1dcf3b79071290d2766 (patch)
tree6446277a8e91cf93a0579460903304272a786443 /runtime/lua/vim/_meta.lua
parent9ce720a6016c9bdc851e6ba909f7329519dd417d (diff)
parent545dc82c1b22709c83ec23e9450f245f9ff1babc (diff)
downloadrneovim-e13dcdf162d166084f19f1dcf3b79071290d2766.tar.gz
rneovim-e13dcdf162d166084f19f1dcf3b79071290d2766.tar.bz2
rneovim-e13dcdf162d166084f19f1dcf3b79071290d2766.zip
Merge pull request #18864 from bfredl/optcut
perf(tests): don't invoke nvim_get_all_options_info until needed
Diffstat (limited to 'runtime/lua/vim/_meta.lua')
-rw-r--r--runtime/lua/vim/_meta.lua45
1 files changed, 29 insertions, 16 deletions
diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua
index 1706956bca..59cf837a1d 100644
--- a/runtime/lua/vim/_meta.lua
+++ b/runtime/lua/vim/_meta.lua
@@ -10,29 +10,39 @@ 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
+local options_info = nil
+local buf_options = nil
+local glb_options = nil
+local win_options = nil
+
+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
-end
-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 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
+
+ return result
end
- return result
+ buf_options = get_scoped_options('buf')
+ glb_options = get_scoped_options('global')
+ win_options = get_scoped_options('win')
end
-local buf_options = get_scoped_options('buf')
-local glb_options = get_scoped_options('global')
-local win_options = get_scoped_options('win')
-
local function make_meta_accessor(get, set, del, validator)
validator = validator or function()
return true
@@ -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