From a3ce4403c6ec97fdadb92e4ffc7ea65bf797112c Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 22 Sep 2021 14:59:56 -0600 Subject: Add a check to the gen_options.lua script to ensure the options are well ordered. (Neo)Vim uses a jump table based on the first character of the option's name. This means for it to work all options with the same first character must be together. If this is violated, some options may seem to disappear, which can sometimes happen during merges if not careful. This commit adds a check to the gen_options.lua script so the build will fail if this constraint is violated. --- src/nvim/generators/gen_options.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 0454c54faf..51ffdae3b0 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -183,6 +183,26 @@ local dump_option = function(i, o) w(' },') end +-- Verify options are correctly ordered. The options with the same first letter +-- must be together or else some of the options may seem to disappear from +-- Neovim. +done_chrs = {} +last_opt = nil +for _, o in ipairs(options.options) do + if (last_opt == nil) then + last_opt = o + elseif last_opt.full_name:sub(1, 1) ~= o.full_name:sub(1, 1) then + done_chrs[last_opt.full_name:sub(1, 1)] = true + last_opt = o + + if done_chrs[o.full_name:sub(1, 1)] then + print("Option '" .. o.full_name .. "' must be next to options with the " + .. "same starting character.") + os.exit(1) + end + end +end + w('static vimoption_T options[] = {') for i, o in ipairs(options.options) do dump_option(i, o) -- cgit