aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-22 12:24:23 +0800
committerGitHub <noreply@github.com>2023-12-22 12:24:23 +0800
commit089b934352437ab310a6dd3b138c7ed9445a3d7b (patch)
tree51de0fb010d97d4bd82aa9674156aae8ab619cdd /src/nvim/generators
parent6700127b30d55e6ddf70495e7b886464172d7ac6 (diff)
downloadrneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.tar.gz
rneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.tar.bz2
rneovim-089b934352437ab310a6dd3b138c7ed9445a3d7b.zip
refactor(options): generate BV_ and WV_ constants (#26705)
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/gen_options_enum.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/nvim/generators/gen_options_enum.lua b/src/nvim/generators/gen_options_enum.lua
index c3fe9baae6..9a3953fcbc 100644
--- a/src/nvim/generators/gen_options_enum.lua
+++ b/src/nvim/generators/gen_options_enum.lua
@@ -1,5 +1,6 @@
-- Generates option index enum and map of option name to option index.
-- Handles option full name, short name and aliases.
+-- Also generates BV_ and WV_ enum constants.
local options_enum_file = arg[1]
local options_map_file = arg[2]
@@ -16,6 +17,9 @@ local function map_w(s)
options_map_fd:write(s .. '\n')
end
+enum_w('// IWYU pragma: private, include "nvim/option_defs.h"')
+enum_w('')
+
--- @param s string
--- @return string
local lowercase_to_titlecase = function(s)
@@ -24,6 +28,55 @@ end
--- @type vim.option_meta[]
local options = require('options').options
+
+-- Generate BV_ enum constants.
+enum_w('/// "indir" values for buffer-local options.')
+enum_w('/// These need to be defined globally, so that the BV_COUNT can be used with')
+enum_w('/// b_p_script_stx[].')
+enum_w('enum {')
+
+local bv_val = 0
+
+for _, o in ipairs(options) do
+ assert(#o.scope == 1 or #o.scope == 2)
+ assert(#o.scope == 1 or o.scope[1] == 'global')
+ local min_scope = o.scope[#o.scope]
+ if min_scope == 'buffer' then
+ local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
+ local bv_name = 'BV_' .. varname:sub(3):upper()
+ enum_w((' %s = %u,'):format(bv_name, bv_val))
+ bv_val = bv_val + 1
+ end
+end
+
+enum_w((' BV_COUNT = %u, ///< must be the last one'):format(bv_val))
+enum_w('};')
+enum_w('')
+
+-- Generate WV_ enum constants.
+enum_w('/// "indir" values for window-local options.')
+enum_w('/// These need to be defined globally, so that the WV_COUNT can be used in the')
+enum_w('/// window structure.')
+enum_w('enum {')
+
+local wv_val = 0
+
+for _, o in ipairs(options) do
+ assert(#o.scope == 1 or #o.scope == 2)
+ assert(#o.scope == 1 or o.scope[1] == 'global')
+ local min_scope = o.scope[#o.scope]
+ if min_scope == 'window' then
+ local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
+ local wv_name = 'WV_' .. varname:sub(3):upper()
+ enum_w((' %s = %u,'):format(wv_name, wv_val))
+ wv_val = wv_val + 1
+ end
+end
+
+enum_w((' WV_COUNT = %u, ///< must be the last one'):format(wv_val))
+enum_w('};')
+enum_w('')
+
--- @type { [string]: string }
local option_index = {}