From 34e2185022ab698827b72751d77e218a1b6b6afe Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 10 Jan 2025 10:20:43 +0000 Subject: fix(options): better handling of empty values Problem: Whether an option is allowed to be empty isn't well defined and isn't properly checked. Solution: - For non-list string options, explicitly check the option value if it is empty. - Annotate non-list string options that can accept an empty value. - Adjust command completion to ignore the empty value. - Render values in Lua meta files --- scripts/gen_eval_files.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index f888972f0d..58d3eeeadc 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -666,7 +666,16 @@ local function render_option_meta(_f, opt, write) write('--- ' .. l) end - write('--- @type ' .. OPTION_TYPES[opt.type]) + if opt.type == 'string' and not opt.list and opt.values then + local values = {} --- @type string[] + for _, e in ipairs(opt.values) do + values[#values + 1] = fmt("'%s'", e) + end + write('--- @type ' .. table.concat(values, '|')) + else + write('--- @type ' .. OPTION_TYPES[opt.type]) + end + write('vim.o.' .. opt.full_name .. ' = ' .. render_option_default(opt.defaults)) if opt.abbreviation then write('vim.o.' .. opt.abbreviation .. ' = vim.o.' .. opt.full_name) -- cgit