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
This commit is contained in:
Lewis Russell
2025-01-10 10:20:43 +00:00
committed by Lewis Russell
parent cb7b4e2962
commit 34e2185022
9 changed files with 72 additions and 42 deletions

View File

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