mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user