diff options
| author | Famiu Haque <famiuhaque@proton.me> | 2023-12-07 01:34:29 +0600 |
|---|---|---|
| committer | Famiu Haque <famiuhaque@proton.me> | 2023-12-14 16:46:42 +0600 |
| commit | 3c2c022e5e299ecac4663c3813e2db5e2b099ffa (patch) | |
| tree | 8cfefb87b8a675e1c29b0caf3e1adca14bf196b5 /src/nvim/generators | |
| parent | 320e9c1c21817fd76b84345018661f70437fa4b5 (diff) | |
| download | rneovim-3c2c022e5e299ecac4663c3813e2db5e2b099ffa.tar.gz rneovim-3c2c022e5e299ecac4663c3813e2db5e2b099ffa.tar.bz2 rneovim-3c2c022e5e299ecac4663c3813e2db5e2b099ffa.zip | |
refactor(options): remove option type macros
Problem: We have `P_(BOOL|NUM|STRING)` macros to represent an option's type, which is redundant because `OptValType` can already do that. The current implementation of option type flags is also too limited to allow adding multitype options in the future.
Solution: Remove `P_(BOOL|NUM|STRING)` and replace it with a new `type_flags` attribute in `vimoption_T`. Also do some groundwork for adding multitype options in the future.
Side-effects: Attempting to set an invalid keycode option (e.g. `set t_foo=123`) no longer gives an error.
Diffstat (limited to 'src/nvim/generators')
| -rw-r--r-- | src/nvim/generators/gen_options.lua | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index b7356a7bb1..61d5df3c84 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -16,12 +16,6 @@ local options = require('options') local cstr = options.cstr -local type_flags = { - bool = 'P_BOOL', - number = 'P_NUM', - string = 'P_STRING', -} - local redraw_flags = { ui_option = 'P_UI_OPTION', tabline = 'P_RTABL', @@ -51,11 +45,14 @@ end --- @param o vim.option_meta --- @return string local function get_flags(o) - --- @type string[] - local ret = { type_flags[o.type] } + --- @type string + local flags = '0' + + --- @param f string local add_flag = function(f) - ret[1] = ret[1] .. '|' .. f + flags = flags .. '|' .. f end + if o.list then add_flag(list_flags[o.list]) end @@ -91,7 +88,22 @@ local function get_flags(o) add_flag(def_name) end end - return ret[1] + return flags +end + +--- @param o vim.option_meta +--- @return string +local function get_type_flags(o) + local opt_types = (type(o.type) == 'table') and o.type or { o.type } + local type_flags = '0' + assert(type(opt_types) == 'table') + + for _, opt_type in ipairs(opt_types) do + assert(type(opt_type) == 'string') + type_flags = ('%s | (1 << kOptValType%s)'):format(type_flags, lowercase_to_titlecase(opt_type)) + end + + return type_flags end --- @param c string|string[] @@ -153,6 +165,7 @@ local function dump_option(i, o) w(' .shortname=' .. cstr(o.abbreviation)) end w(' .flags=' .. get_flags(o)) + w(' .type_flags=' .. get_type_flags(o)) if o.enable_if then w(get_cond(o.enable_if)) end |