feat: improve lint logic
This commit is contained in:
@@ -296,14 +296,28 @@ function M.lint.setup()
|
||||
once = true,
|
||||
callback = function()
|
||||
local lint = require('lint')
|
||||
lint.linters_by_ft = (M.general and M.general.linters_by_ft) or {}
|
||||
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
|
||||
lint.linters_by_ft = M.general.linters_by_ft
|
||||
|
||||
function M.debounce(ms, fn)
|
||||
local timer = vim.uv.new_timer()
|
||||
return function(...)
|
||||
local argv = { ... }
|
||||
timer:start(ms, 0, function()
|
||||
timer:stop()
|
||||
vim.schedule_wrap(fn)(unpack(argv))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function M.lint()
|
||||
if vim.bo.modifiable then
|
||||
lint.try_lint()
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufReadPost', 'InsertLeave', 'TextChanged' }, {
|
||||
group = vim.api.nvim_create_augroup('language-manager.lint', { clear = true }),
|
||||
callback = function()
|
||||
if vim.bo.modifiable then
|
||||
lint.try_lint()
|
||||
end
|
||||
end,
|
||||
callback = M.debounce(100, M.lint),
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user