Use apply_text_edits to avoid making the unexpected indentation by '<CR>'
This commit is contained in:
@@ -35,6 +35,18 @@ async.throttle = function(fn, timeout)
|
||||
})
|
||||
end
|
||||
|
||||
---Control async tasks.
|
||||
async.step = function(...)
|
||||
local tasks = { ... }
|
||||
local next
|
||||
next = function()
|
||||
if #tasks > 0 then
|
||||
table.remove(tasks, 1)(next)
|
||||
end
|
||||
end
|
||||
table.remove(tasks, 1)(next)
|
||||
end
|
||||
|
||||
---Timeout callback function
|
||||
---@param fn function
|
||||
---@param timeout number
|
||||
|
||||
@@ -40,4 +40,30 @@ describe('utils.async', function()
|
||||
end)
|
||||
assert.is.truthy(math.abs(vim.loop.now() - now) < 10)
|
||||
end)
|
||||
it('step', function()
|
||||
local done = false
|
||||
local step = {}
|
||||
async.step(function(next)
|
||||
vim.defer_fn(function()
|
||||
table.insert(step, 1)
|
||||
next()
|
||||
end, 10)
|
||||
end, function(next)
|
||||
vim.defer_fn(function()
|
||||
table.insert(step, 2)
|
||||
next()
|
||||
end, 10)
|
||||
end, function(next)
|
||||
vim.defer_fn(function()
|
||||
table.insert(step, 3)
|
||||
next()
|
||||
end, 10)
|
||||
end, function()
|
||||
done = true
|
||||
end)
|
||||
vim.wait(1000, function()
|
||||
return done
|
||||
end)
|
||||
assert.are.same(step, { 1, 2, 3 })
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user