From a8c2c54b1f6f4fa2665fe2b6c71926d24112d72a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 12 Oct 2024 15:52:07 +1100 Subject: [PATCH] chore: add utils.enumerate_options --- lua/nvim-tree/utils.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 495e6679f14..b48e989b483 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -571,4 +571,32 @@ function M.is_executable(absolute_path) end end +---List of all option info/values +---@param opts vim.api.keyset.option passed directly to vim.api.nvim_get_option_info2 and vim.api.nvim_get_option_value +---@param was_set boolean filter was_set +---@return { info: vim.api.keyset.get_option_info, val: any }[] +function M.enumerate_options(opts, was_set) + local res = {} + + local infos = vim.tbl_filter(function(info) + if opts.buf and info.scope ~= "buf" then + return false + elseif opts.win and info.scope ~= "win" then + return false + else + return true + end + end, vim.api.nvim_get_all_options_info()) + + for _, info in vim.spairs(infos) do + local _, info2 = pcall(vim.api.nvim_get_option_info2, info.name, opts) + if not was_set or info2.was_set then + local val = pcall(vim.api.nvim_get_option_value, info.name, opts) + table.insert(res, { info = info2, val = val }) + end + end + + return res +end + return M