From 1d3ee1c44186c211611abd03bdb4e38004b14ff4 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 11:13:43 -0400 Subject: fix(vim.opt): #14708 Now lets you put duplicate values in wildmode --- runtime/lua/vim/_meta.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 02d1154df4..85861420aa 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -325,9 +325,12 @@ local convert_value_to_vim = (function() return result end, - [OptionTypes.ARRAY] = function(_, value) + [OptionTypes.ARRAY] = function(info, value) if type(value) == "string" then return value end - return table.concat(remove_duplicate_values(value), ",") + if not info.allows_duplicates then + value = remove_duplicate_values(value) + end + return table.concat(value, ",") end, [OptionTypes.MAP] = function(_, value) -- cgit From e6175f6389ea3fdc685fe2158948d49caa8cdba2 Mon Sep 17 00:00:00 2001 From: ckipp01 Date: Sun, 30 May 2021 13:08:43 +0200 Subject: fix(vim.opt): Get window options before setting. This closes #14677, but I also am a little unsure if there are times where this may not be correct. However, this just changes the behavior that even if `was_set` was false, we still get for `nvim_win_get_option`. --- runtime/lua/vim/_meta.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 85861420aa..c3f3bf66d3 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -209,12 +209,17 @@ local function get_scoped_option(k, set_type) end if is_window_option(info) then - if vim.api.nvim_get_option_info(k).was_set then - local was_set, value = pcall(a.nvim_win_get_option, 0, k) - if was_set then return value end + local ok, value = pcall(a.nvim_win_get_option, 0, k) + if ok then + return value end - return a.nvim_get_option(k) + local global_ok, global_val = pcall(a.nvim_get_option, k) + if global_ok then + return global_val + end + + error("win_get: This should never happen. File an issue and tag @tjdevries") end error("This fallback case should not be possible. " .. k) -- cgit From b02e64c4dffd9044ea83e3f2d74b5f6db6bf6b99 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Sun, 30 May 2021 20:49:19 +0800 Subject: fix(vim.opt): Add basic error handling --- runtime/lua/vim/_meta.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index c3f3bf66d3..92c8fe0e26 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -311,6 +311,28 @@ local get_option_type = function(name, info) end +-- Check whether the OptionTypes is allowed for vim.opt +-- If it does not match, throw an error which indicates which option causes the error. +local function assert_valid_value(name, value, types) + local type_of_value = type(value) + for _, valid_type in ipairs(types) do + if valid_type == type_of_value then + return + end + end + + error(string.format("Invalid option type '%s' for '%s', should be %s", type_of_value, name, table.concat(types, " or "))) +end + +local valid_types = { + [OptionTypes.BOOLEAN] = { "boolean" }, + [OptionTypes.NUMBER] = { "number" }, + [OptionTypes.STRING] = { "string" }, + [OptionTypes.SET] = { "string", "table" }, + [OptionTypes.ARRAY] = { "string", "table" }, + [OptionTypes.MAP] = { "string", "table" }, +} + --- Convert a lua value to a vimoption_T value local convert_value_to_vim = (function() -- Map of functions to take a Lua style value and convert to vimoption_T style value. @@ -340,7 +362,6 @@ local convert_value_to_vim = (function() [OptionTypes.MAP] = function(_, value) if type(value) == "string" then return value end - if type(value) == "function" then error(debug.traceback("asdf")) end local result = {} for opt_key, opt_value in pairs(value) do @@ -353,7 +374,10 @@ local convert_value_to_vim = (function() } return function(name, info, value) - return to_vim_value[get_option_type(name, info)](info, value) + local option_type = get_option_type(name, info) + assert_valid_value(name, value, valid_types[option_type]) + + return to_vim_value[option_type](info, value) end end)() -- cgit From 9119ea1becd5024ad14db04e2868feeae7c7d4de Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 12:28:15 -0400 Subject: fix(vim.opt): Fix #14669 whichwrap now acts as expected --- runtime/lua/vim/_meta.lua | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 92c8fe0e26..e030c9ac81 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -267,7 +267,7 @@ local key_value_options = { winhl = true, } ----@class OptionType +---@class OptionTypes --- Option Type Enum local OptionTypes = setmetatable({ BOOLEAN = 0, @@ -342,14 +342,29 @@ local convert_value_to_vim = (function() [OptionTypes.NUMBER] = function(_, value) return value end, [OptionTypes.STRING] = function(_, value) return value end, - [OptionTypes.SET] = function(_, value) + [OptionTypes.SET] = function(info, value) if type(value) == "string" then return value end - local result = '' - for k in pairs(value) do - result = result .. k - end - return result + if info.flaglist and info.commalist then + local keys = {} + for k, v in pairs(value) do + if v then + table.insert(keys, k) + end + end + + table.sort(keys) + return table.concat(keys, ",") + else + local result = '' + for k, v in pairs(value) do + if v then + result = result .. k + end + end + + return result + end end, [OptionTypes.ARRAY] = function(info, value) @@ -404,12 +419,22 @@ local convert_value_to_lua = (function() assert(info.flaglist, "That is the only one I know how to handle") - local result = {} - for i = 1, #value do - result[value:sub(i, i)] = true - end + if info.flaglist and info.commalist then + local split_value = vim.split(value, ",") + local result = {} + for _, v in ipairs(split_value) do + result[v] = true + end - return result + return result + else + local result = {} + for i = 1, #value do + result[value:sub(i, i)] = true + end + + return result + end end, [OptionTypes.MAP] = function(info, raw_value) -- cgit From 6ecec87c099ce6182b4a1cc81846be9e0e70c1cd Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 11 Jun 2021 13:39:59 -0400 Subject: fix(vim.opt): Fix #14668 Now correctly handles unescaped commas in isfname style --- runtime/lua/vim/_meta.lua | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index e030c9ac81..416746b2cc 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -405,12 +405,46 @@ local convert_value_to_lua = (function() [OptionTypes.NUMBER] = function(_, value) return value end, [OptionTypes.STRING] = function(_, value) return value end, - [OptionTypes.ARRAY] = function(_, value) + [OptionTypes.ARRAY] = function(info, value) if type(value) == "table" then - value = remove_duplicate_values(value) + if not info.allows_duplicates then + value = remove_duplicate_values(value) + end + return value end + -- Handles unescaped commas in a list. + if string.find(value, ",,,") then + local comma_split = vim.split(value, ",,,") + local left = comma_split[1] + local right = comma_split[2] + + local result = {} + vim.list_extend(result, vim.split(left, ",")) + table.insert(result, ",") + vim.list_extend(result, vim.split(right, ",")) + + table.sort(result) + + return result + end + + if string.find(value, ",^,,", 1, true) then + local comma_split = vim.split(value, ",^,,", true) + local left = comma_split[1] + local right = comma_split[2] + + local result = {} + vim.list_extend(result, vim.split(left, ",")) + table.insert(result, "^,") + vim.list_extend(result, vim.split(right, ",")) + + table.sort(result) + + return result + end + return vim.split(value, ",") end, -- cgit From 19b7cef0a7dc52f3ec016e0dd0ae82f0f6ecd4b1 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 29 Jun 2021 09:18:59 -0400 Subject: fix(vim.opt): Fix #14828 with empty values being incorrectly inserted --- runtime/lua/vim/_meta.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 416746b2cc..b1f935541c 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -414,6 +414,12 @@ local convert_value_to_lua = (function() return value end + -- Empty strings mean that there is nothing there, + -- so empty table should be returned. + if value == '' then + return {} + end + -- Handles unescaped commas in a list. if string.find(value, ",,,") then local comma_split = vim.split(value, ",,,") @@ -451,6 +457,12 @@ local convert_value_to_lua = (function() [OptionTypes.SET] = function(info, value) if type(value) == "table" then return value end + -- Empty strings mean that there is nothing there, + -- so empty table should be returned. + if value == '' then + return {} + end + assert(info.flaglist, "That is the only one I know how to handle") if info.flaglist and info.commalist then -- cgit