Skip to content

Commit 27b7160

Browse files
committed
fix: adjust to vim.validate deprecation
1 parent 69c70e8 commit 27b7160

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

lua/telescope/actions/utils.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
---@brief ]]
99

1010
local action_state = require "telescope.actions.state"
11+
local validate = require("telescope.utils").validate
1112

1213
local utils = {}
1314

@@ -35,9 +36,8 @@ local utils = {}
3536
---@param prompt_bufnr number: The prompt bufnr
3637
---@param f function: Function to map onto entries of picker that takes (entry, index, row) as viable arguments
3738
function utils.map_entries(prompt_bufnr, f)
38-
vim.validate {
39-
f = { f, "function" },
40-
}
39+
validate("f", f, "function")
40+
4141
local current_picker = action_state.get_current_picker(prompt_bufnr)
4242
local index = 1
4343
-- indices are 1-indexed, rows are 0-indexed
@@ -72,9 +72,8 @@ end
7272
---@param prompt_bufnr number: The prompt bufnr
7373
---@param f function: Function to map onto selection of picker that takes (selection) as a viable argument
7474
function utils.map_selections(prompt_bufnr, f)
75-
vim.validate {
76-
f = { f, "function" },
77-
}
75+
validate("f", f, "function")
76+
7877
local current_picker = action_state.get_current_picker(prompt_bufnr)
7978
for _, selection in ipairs(current_picker:get_multi_selection()) do
8079
f(selection)

lua/telescope/debounce.lua

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33

44
local M = {}
55

6+
---TODO(clason): duplicate for performance reason
7+
---remove when dropping support for Nvim 0.10
8+
local nvim011 = vim.fn.has "nvim-0.11" == 1
9+
local validate = function(k, v, ty, errmsg)
10+
if nvim011 then
11+
vim.validate(k, v, ty, errmsg)
12+
else
13+
vim.validate { [k] = { v, ty, errmsg }}
14+
end
15+
end
16+
617
---Validates args for `throttle()` and `debounce()`.
718
local function td_validate(fn, ms)
8-
vim.validate {
9-
fn = { fn, "f" },
10-
ms = {
11-
ms,
12-
function(v)
13-
return type(v) == "number" and v > 0
14-
end,
15-
"number > 0",
16-
},
17-
}
19+
validate("fn", fn, "function")
20+
validate("ms", ms, function(v)
21+
return type(v) == "number" and v > 0
22+
end, "number > 0")
1823
end
1924

2025
--- Throttles a function on the leading edge. Automatically `schedule_wrap()`s.

lua/telescope/pickers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,8 @@ end
816816
--- - `actions.delete_buffer()`
817817
---@param delete_cb function: called for each selection fn(s) -> bool|nil (true|nil removes the entry from the results)
818818
function Picker:delete_selection(delete_cb)
819-
vim.validate { delete_cb = { delete_cb, "f" } }
819+
utils.validate("delete_cb", delete_cb, "function")
820+
820821
local original_selection_strategy = self.selection_strategy
821822
self.selection_strategy = "row"
822823

lua/telescope/utils.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,23 @@ utils.str_byteindex = function(s, i, encoding)
3030
end
3131
end
3232

33+
---@param t table
3334
utils.flatten = function(t)
3435
return vim.iter(t):flatten():totable()
3536
end
3637

38+
---TODO(clason): remove when dropping support for Nvim 0.10
39+
---@param k string
40+
---@param v any
41+
---@param ty type
42+
utils.validate = function(k, v, ty)
43+
if utils.nvim011 then
44+
vim.validate(k, v, ty)
45+
else
46+
vim.validate { [k] = { v, ty } }
47+
end
48+
end
49+
3750
--- Hybrid of `vim.fn.expand()` and custom `vim.fs.normalize()`
3851
---
3952
--- Paths starting with '%', '#' or '<' are expanded with `vim.fn.expand()`.
@@ -52,9 +65,7 @@ end
5265
---@param path string
5366
---@return string
5467
utils.path_expand = function(path)
55-
vim.validate {
56-
path = { path, { "string" } },
57-
}
68+
utils.validate("path", path, "string")
5869

5970
if utils.is_uri(path) then
6071
return path

0 commit comments

Comments
 (0)