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.
This commit is contained in:
Famiu Haque
2023-12-07 01:34:29 +06:00
parent 320e9c1c21
commit 3c2c022e5e
16 changed files with 553 additions and 524 deletions

View File

@@ -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