Something went wrong. Try again.
Just a preview for Neovim's quickfix list
Something went wrong. Try again.
871 B · 49 lines
Lua
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950local M = {}
---@class qfpreview.util.Throttled---@operator call: ...---@field cancel fun(self: qfpreview.util.Throttled)
---@generic P---@param fn fun(...: P)---@param delay_ms number---@return qfpreview.util.Throttled | fun(...: P)function M.throttle(fn, delay_ms) local timer = vim.uv.new_timer()
---@type qfpreview.util.Throttled local t = { cancel = function() end, }
if not timer then setmetatable(t, { __call = function(_, ...) return fn(...) end, }) return t end
setmetatable(t, { __call = function(_, ...) local args = { ... } timer:stop() timer:start(delay_ms, 0, function() vim.schedule(function() fn(unpack(args)) end) end) end, })
function t:cancel() timer:stop() timer:close() timer = nil end
return tend
return M