* dev

* Improve sync design

* Support buffer local mapping

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* stylua

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* integration

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* update

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp
This commit is contained in:
hrsh7th
2021-08-04 01:07:12 +09:00
committed by GitHub
parent b32a6e7e77
commit d23d3533cf
53 changed files with 4681 additions and 0 deletions

55
lua/cmp/utils/async.lua Normal file
View File

@@ -0,0 +1,55 @@
local async = {}
---@class cmp.AsyncThrottle
---@field public timeout number
---@field public stop function
---@field public __call function
---@param fn function
---@param timeout number
---@return cmp.AsyncThrottle
async.throttle = function(fn, timeout)
local time = nil
local timer = vim.loop.new_timer()
return setmetatable({
timeout = timeout,
stop = function()
time = nil
timer:stop()
end,
}, {
__call = function(self, ...)
local args = { ... }
if time == nil then
time = vim.loop.now()
end
timer:stop()
local delta = math.max(0, self.timeout - (vim.loop.now() - time))
timer:start(delta, 0, vim.schedule_wrap(function()
time = nil
fn(unpack(args))
end))
end
})
end
---Create deduplicated callback
---@return function
async.dedup = function()
local id = 0
return function(callback)
id = id + 1
local current = id
return function(...)
if current == id then
callback(...)
end
end
end
end
return async