Skip to content

Commit 0a4469b

Browse files
committed
fix: allow nil arguments to debounce function
this allows ```lua local f = utils.debounce(function(...) print(...) end) f(1, nil, 9, nil, nil) -- "1 nil 9 nil nil" --- previously would've output "1" (undefined behavior) ```
1 parent 5e813f8 commit 0a4469b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lua/tabnine/utils.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ local api = vim.api
44
local M = {}
55
local last_changedtick = vim.b.changedtick
66

7+
---@param func fun(...: unknown): any the callback
8+
---@param delay integer delay in milliseconds
9+
---@return fun(...: unknown)
710
function M.debounce(func, delay)
811
local timer_id
912
return function(...)
1013
if timer_id then fn.timer_stop(timer_id) end
11-
local args = { ... }
14+
local args = table.pack(...)
1215
timer_id = fn.timer_start(delay, function()
13-
func(unpack(args))
16+
return func(unpack(args, 1, args.n))
1417
end)
1518
end
1619
end

0 commit comments

Comments
 (0)