Skip to content

Commit

Permalink
feat: re-enable neovim 0.11 vim.validate
Browse files Browse the repository at this point in the history
Closes #1275
  • Loading branch information
Saghen committed Feb 19, 2025
1 parent 3a97722 commit 22e6351
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 13 additions & 9 deletions lua/blink/cmp/config/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ local utils = {}
--- NOTE: We disable some Lua diagnostics here since lua_ls isn't smart enough to
--- realize that we're using an overloaded function.
function utils._validate(spec)
return vim.validate(spec)
-- if vim.fn.has('nvim-0.11') == 0 then return vim.validate(spec) end
-- for key, key_spec in pairs(spec) do
-- local message = type(key_spec[3]) == 'string' and key_spec[3] or nil --[[@as string?]]
-- local optional = type(key_spec[3]) == 'boolean' and key_spec[3] or nil --[[@as boolean?]]
-- ---@diagnostic disable-next-line:param-type-mismatch, redundant-parameter
-- vim.validate(key, key_spec[1], key_spec[2], optional, message)
-- end
if vim.fn.has('nvim-0.11') == 0 then return vim.validate(spec) end
for key, key_spec in pairs(spec) do
local message = type(key_spec[3]) == 'string' and key_spec[3] or nil --[[@as string?]]
local optional = type(key_spec[3]) == 'boolean' and key_spec[3] or nil --[[@as boolean?]]
vim.validate(key, key_spec[1], key_spec[2], optional, message)
end
end

--- @param path string The path to the field being validated
Expand All @@ -25,7 +23,13 @@ end
--- @see vim.validate
function utils.validate(path, tbl, source)
-- validate
local _, err = pcall(vim.validate, tbl)
local _, err = pcall(utils._validate, tbl)
-- remove stack trace from error message
if err ~= nil and vim.fn.has('nvim-0.11') == 1 then
local slice = require('blink.cmp.lib.utils').slice

err = table.concat(slice(vim.split(err, ':'), 3), ':'):gsub('^%s+', '')
end
if err then error(path .. '.' .. err) end

-- check for erroneous fields
Expand Down
10 changes: 7 additions & 3 deletions lua/blink/cmp/sources/snippets/mini_snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ local defaults_config = {

function source.new(opts)
local config = vim.tbl_deep_extend('keep', opts, defaults_config)
vim.validate({
use_items_cache = { config.use_items_cache, 'boolean' },
})
vim.validate(
'snippets.opts.use_items_cache',
config.use_items_cache,
'boolean',
false,
'use_items_cache must be a boolean when using mini__nippets preset'
)

local self = setmetatable({}, { __index = source })
self.config = config
Expand Down

0 comments on commit 22e6351

Please sign in to comment.