fix StyLua command (#190)
* style: fix StyLua glob pattern * style: fix style with StyLua run './utils/stylua --config-path stylua.toml --glob 'lua/**/*.lua' -- lua'
This commit is contained in:
@@ -27,11 +27,15 @@ async.throttle = function(fn, timeout)
|
||||
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
|
||||
timer:start(
|
||||
delta,
|
||||
0,
|
||||
vim.schedule_wrap(function()
|
||||
time = nil
|
||||
fn(unpack(args))
|
||||
end)
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -52,4 +56,3 @@ async.dedup = function()
|
||||
end
|
||||
|
||||
return async
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
local async = require "cmp.utils.async"
|
||||
local async = require('cmp.utils.async')
|
||||
|
||||
describe('utils.async', function()
|
||||
|
||||
it('throttle', function()
|
||||
local count = 0
|
||||
local now
|
||||
@@ -13,14 +12,18 @@ describe('utils.async', function()
|
||||
now = vim.loop.now()
|
||||
f.timeout = 100
|
||||
f()
|
||||
vim.wait(1000, function() return count == 1 end)
|
||||
vim.wait(1000, function()
|
||||
return count == 1
|
||||
end)
|
||||
assert.is.truthy(math.abs(f.timeout - (vim.loop.now() - now)) < 10)
|
||||
|
||||
-- 2. delay for 500ms
|
||||
now = vim.loop.now()
|
||||
f.timeout = 500
|
||||
f()
|
||||
vim.wait(1000, function() return count == 2 end)
|
||||
vim.wait(1000, function()
|
||||
return count == 2
|
||||
end)
|
||||
assert.is.truthy(math.abs(f.timeout - (vim.loop.now() - now)) < 10)
|
||||
|
||||
-- 4. delay for 500ms and wait 100ms (remain 400ms)
|
||||
@@ -32,9 +35,9 @@ describe('utils.async', function()
|
||||
now = vim.loop.now()
|
||||
f.timeout = 100
|
||||
f()
|
||||
vim.wait(1000, function() return count == 3 end)
|
||||
vim.wait(1000, function()
|
||||
return count == 3
|
||||
end)
|
||||
assert.is.truthy(math.abs(vim.loop.now() - now) < 10)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
@@ -54,4 +54,3 @@ cache.key = function(_, key)
|
||||
end
|
||||
|
||||
return cache
|
||||
|
||||
|
||||
@@ -110,4 +110,3 @@ char.match = function(byte1, byte2)
|
||||
end
|
||||
|
||||
return char
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ keymap.escape = function(keys)
|
||||
while i <= #keys do
|
||||
if string.sub(keys, i, i) == '<' then
|
||||
if not vim.tbl_contains({ '<lt>', '<Lt>', '<lT>', '<LT>' }, string.sub(keys, i, i + 3)) then
|
||||
keys = string.sub(keys, 1, i -1) .. '<LT>' .. string.sub(keys, i + 1)
|
||||
keys = string.sub(keys, 1, i - 1) .. '<LT>' .. string.sub(keys, i + 1)
|
||||
i = i + 3
|
||||
end
|
||||
end
|
||||
@@ -80,7 +80,7 @@ end
|
||||
|
||||
---Feedkeys with callback
|
||||
keymap.feedkeys = setmetatable({
|
||||
callbacks = {}
|
||||
callbacks = {},
|
||||
}, {
|
||||
__call = function(self, keys, mode, callback)
|
||||
if #keys ~= 0 then
|
||||
@@ -104,7 +104,7 @@ keymap.feedkeys = setmetatable({
|
||||
wait()
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
misc.set(_G, { 'cmp', 'utils', 'keymap', 'feedkeys', 'run' }, function(id)
|
||||
if keymap.feedkeys.callbacks[id] then
|
||||
@@ -201,4 +201,3 @@ misc.set(_G, { 'cmp', 'utils', 'keymap', 'listen', 'run' }, function(mode, keys)
|
||||
end)
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ end
|
||||
---@param v2 T
|
||||
---@return T
|
||||
misc.merge = function(v1, v2)
|
||||
local merge1 = type(v1) == "table" and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1))
|
||||
local merge2 = type(v2) == "table" and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1))
|
||||
local merge1 = type(v1) == 'table' and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1))
|
||||
local merge2 = type(v2) == 'table' and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1))
|
||||
if merge1 and merge2 then
|
||||
local new_tbl = {}
|
||||
for k, v in pairs(v2) do
|
||||
@@ -48,16 +48,15 @@ misc.merge = function(v1, v2)
|
||||
return v1
|
||||
end
|
||||
|
||||
|
||||
---Generate id for group name
|
||||
misc.id = setmetatable({
|
||||
group = {}
|
||||
group = {},
|
||||
}, {
|
||||
__call = function(_, group)
|
||||
misc.id.group[group] = misc.id.group[group] or 0
|
||||
misc.id.group[group] = misc.id.group[group] + 1
|
||||
return misc.id.group[group]
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
---Check the value is nil or not.
|
||||
|
||||
@@ -8,21 +8,20 @@ describe('misc', function()
|
||||
it('merge', function()
|
||||
local merged
|
||||
merged = misc.merge({
|
||||
a = {}
|
||||
a = {},
|
||||
}, {
|
||||
a = {
|
||||
b = 1
|
||||
}
|
||||
b = 1,
|
||||
},
|
||||
})
|
||||
assert.are.equal(merged.a.b, 1)
|
||||
merged = misc.merge({
|
||||
a = false
|
||||
a = false,
|
||||
}, {
|
||||
a = {
|
||||
b = 1
|
||||
}
|
||||
b = 1,
|
||||
},
|
||||
})
|
||||
assert.are.equal(merged.a, false)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -26,4 +26,3 @@ pattern.matchstr = function(p, text)
|
||||
end
|
||||
|
||||
return pattern
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
local context = require'cmp.context'
|
||||
local source = require 'cmp.source'
|
||||
local context = require('cmp.context')
|
||||
local source = require('cmp.source')
|
||||
local types = require('cmp.types')
|
||||
|
||||
local spec = {}
|
||||
|
||||
spec.before = function()
|
||||
vim.cmd [[
|
||||
vim.cmd([[
|
||||
bdelete!
|
||||
enew!
|
||||
setlocal virtualedit=all
|
||||
]]
|
||||
]])
|
||||
end
|
||||
|
||||
spec.state = function(text, row, col)
|
||||
@@ -17,8 +17,7 @@ spec.state = function(text, row, col)
|
||||
vim.fn.cursor(row, col)
|
||||
local ctx = context.empty()
|
||||
local s = source.new('spec', {
|
||||
complete = function()
|
||||
end
|
||||
complete = function() end,
|
||||
})
|
||||
return {
|
||||
context = function()
|
||||
@@ -46,9 +45,8 @@ spec.state = function(text, row, col)
|
||||
ctx = context.new(ctx, { reason = types.cmp.ContextReason.Manual })
|
||||
s:complete(ctx, function() end)
|
||||
return ctx
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return spec
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local char = require'cmp.utils.char'
|
||||
local pattern = require 'cmp.utils.pattern'
|
||||
local char = require('cmp.utils.char')
|
||||
local pattern = require('cmp.utils.pattern')
|
||||
|
||||
local str = {}
|
||||
|
||||
@@ -179,4 +179,3 @@ str.escape = function(text, chars)
|
||||
end
|
||||
|
||||
return str
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
local str = require "cmp.utils.str"
|
||||
local str = require('cmp.utils.str')
|
||||
|
||||
describe('utils.str', function()
|
||||
|
||||
it('get_word', function()
|
||||
assert.are.equal(str.get_word('print'), 'print')
|
||||
assert.are.equal(str.get_word('$variable'), '$variable')
|
||||
@@ -27,7 +26,4 @@ describe('utils.str', function()
|
||||
assert.are.equal(str.escape('plain\\"', {}), 'plain\\\\"')
|
||||
assert.are.equal(str.escape('pla"in', { '"' }), 'pla\\"in')
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user