Skip to content

Commit

Permalink
fix(ALL): adjust after vim.tbl_deep_extend change on Nightly
Browse files Browse the repository at this point in the history
It now merges tables on any level regardless of whether it is array or
not. This seems like a better behavior, which needs adjusting in several
places working with extending array table items (and need to prefer full
array from the user instead of cherry-picking array elements).
  • Loading branch information
echasnovski committed Sep 5, 2024
1 parent 7874974 commit 14f81b9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lua/mini/ai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ MiniAi.gen_spec = {}
--- Default: `{ '%b""', "%b''", '%b()', '%b[]', '%b{}' }` (separators
--- inside balanced quotes or brackets are ignored).
MiniAi.gen_spec.argument = function(opts)
opts = vim.tbl_deep_extend('force', {
opts = vim.tbl_extend('force', {
brackets = { '%b()', '%b[]', '%b{}' },
separator = ',',
exclude_regions = { '%b""', "%b''", '%b()', '%b[]', '%b{}' },
Expand Down
9 changes: 6 additions & 3 deletions lua/mini/align.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,10 @@ end

H.is_disabled = function() return vim.g.minialign_disable == true or vim.b.minialign_disable == true end

H.get_config = function(config)
return vim.tbl_deep_extend('force', MiniAlign.config, vim.b.minialign_config or {}, config or {})
H.get_config = function()
-- Using `tbl_deep_extend()` works even in presense of `steps.pre_*` arrays
-- because default ones are empty.
return vim.tbl_deep_extend('force', MiniAlign.config, vim.b.minialign_config or {})
end

-- Mappings -------------------------------------------------------------------
Expand Down Expand Up @@ -1396,7 +1398,8 @@ end

H.normalize_steps = function(steps, steps_name)
-- Infer all defaults from module config
local res = vim.tbl_deep_extend('force', H.get_config().steps, steps or {})
-- NOTE: Don't use `tbl_deep_extend` to prefer full input arrays (if present)
local res = vim.tbl_extend('force', H.get_config().steps, steps or {})

H.validate_steps(res, steps_name)

Expand Down
9 changes: 3 additions & 6 deletions lua/mini/bracketed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1135,12 +1135,9 @@ MiniBracketed.yank = function(direction, opts)
if H.is_disabled() then return end

H.validate_direction(direction, { 'first', 'backward', 'forward', 'last' }, 'yank')
opts = vim.tbl_deep_extend(
'force',
{ n_times = vim.v.count1, operators = { 'c', 'd', 'y' }, wrap = true },
H.get_config().yank.options,
opts or {}
)
-- NOTE: Don't use `tbl_deep_extend` to prefer full input `operators` array
local default_opts = { n_times = vim.v.count1, operators = { 'c', 'd', 'y' }, wrap = true }
opts = vim.tbl_extend('force', default_opts, H.get_config().yank.options, opts or {})

-- Update yank history data
local cache_yank, history = H.cache.yank, H.cache.yank.history
Expand Down
4 changes: 3 additions & 1 deletion lua/mini/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ H.setup_config = function(config)
-- General idea: if some table elements are not present in user-supplied
-- `config`, take them from default config
vim.validate({ config = { config, 'table', true } })
config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})
-- NOTE: Don't use `tbl_deep_extend` to prefer full input `make_global` array
-- Needs adjusting if there is a new setting with nested tables
config = vim.tbl_extend('force', vim.deepcopy(H.default_config), config or {})

vim.validate({
make_global = {
Expand Down
14 changes: 7 additions & 7 deletions lua/mini/surround.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1309,20 +1309,20 @@ end

H.make_surrounding_table = function()
-- Extend builtins with data from `config`
local surroundings = vim.tbl_deep_extend('force', H.builtin_surroundings, H.get_config().custom_surroundings or {})

-- Add possibly missing information from default surrounding info
for char, info in pairs(surroundings) do
local surroundings = vim.deepcopy(H.builtin_surroundings)
for char, spec in pairs(H.get_config().custom_surroundings or {}) do
local cur_spec = surroundings[char] or {}
local default = H.get_default_surrounding_info(char)
surroundings[char] = vim.tbl_deep_extend('force', default, info)
-- NOTE: Don't use `tbl_deep_extend` to prefer full `input` arrays
cur_spec.input = spec.input or cur_spec.input or default.input
cur_spec.output = spec.output or cur_spec.output or default.output
surroundings[char] = cur_spec
end

-- Use default surrounding info for not supplied single character identifier
--stylua: ignore start
return setmetatable(surroundings, {
__index = function(_, key) return H.get_default_surrounding_info(key) end,
})
--stylua: ignore end
end

H.get_default_surrounding_info = function(char)
Expand Down

0 comments on commit 14f81b9

Please sign in to comment.