Skip to content

Commit

Permalink
fix: use non-deprecated versions of vim.validate for newer neovim ver…
Browse files Browse the repository at this point in the history
…sions

This will remove stack traces from `:checkhealth vim.deprecated`.
  • Loading branch information
dundargoc committed Jan 28, 2025
1 parent 12ebac8 commit f903035
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 13 additions & 3 deletions lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1268,22 +1268,32 @@ H.opened_buffers = {}
-- File system information
H.is_windows = vim.loop.os_uname().sysname == 'Windows_NT'

local function validate(t)
if vim.fn.has('nvim-0.11') == 1 then
for k, v in pairs(t) do
vim.validate(k, v[1], v[2], v[3])
end
else
vim.validate(t)
end
end

-- Helper functionality =======================================================
-- Settings -------------------------------------------------------------------
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 } })
validate({ config = { config, 'table', true } })
config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})

vim.validate({
validate({
content = { config.content, 'table' },
mappings = { config.mappings, 'table' },
options = { config.options, 'table' },
windows = { config.windows, 'table' },
})

vim.validate({
validate({
['content.filter'] = { config.content.filter, 'function', true },
['content.prefix'] = { config.content.prefix, 'function', true },
['content.sort'] = { config.content.sort, 'function', true },
Expand Down
16 changes: 13 additions & 3 deletions lua/mini/operators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,23 +665,33 @@ H.submode_keys = {
block = vim.api.nvim_replace_termcodes('<C-v>', true, true, true),
}

local function validate(t)
if vim.fn.has('nvim-0.11') == 1 then
for k, v in pairs(t) do
vim.validate(k, v[1], v[2], v[3])
end
else
vim.validate(t)
end
end

-- Helper functionality =======================================================
-- Settings -------------------------------------------------------------------
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 } })
validate({ config = { config, 'table', true } })
config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})

vim.validate({
validate({
evaluate = { config.evaluate, 'table' },
exchange = { config.exchange, 'table' },
multiply = { config.multiply, 'table' },
replace = { config.replace, 'table' },
sort = { config.sort, 'table' },
})

vim.validate({
validate({
['evaluate.prefix'] = { config.evaluate.prefix, 'string' },
['evaluate.func'] = { config.evaluate.func, 'function', true },

Expand Down
16 changes: 13 additions & 3 deletions lua/mini/splitjoin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -729,22 +729,32 @@ H.ns_id = vim.api.nvim_create_namespace('MiniSplitjoin')

H.cache = { operator_task = nil }

local function validate(t)
if vim.fn.has('nvim-0.11') == 1 then
for k, v in pairs(t) do
vim.validate(k, v[1], v[2], v[3])
end
else
vim.validate(t)
end
end

-- Helper functionality =======================================================
-- Settings -------------------------------------------------------------------
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 } })
validate({ config = { config, 'table', true } })
config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})

vim.validate({
validate({
mappings = { config.mappings, 'table' },
detect = { config.detect, 'table' },
split = { config.split, 'table' },
join = { config.join, 'table' },
})

vim.validate({
validate({
['mappings.toggle'] = { config.mappings.toggle, 'string', true },
['mappings.split'] = { config.mappings.split, 'string' },
['mappings.join'] = { config.mappings.join, 'string', true },
Expand Down

0 comments on commit f903035

Please sign in to comment.