feat: improve lint logic

This commit is contained in:
Tomas Mirchev 2025-10-26 05:49:02 +02:00
parent a4b5accc05
commit ae3d2d20ee
3 changed files with 26 additions and 13 deletions

View File

@ -20,7 +20,7 @@ au('VimEnter', {
au('TextYankPost', {
group = group,
callback = function()
vim.highlight.on_yank({ timeout = 400 })
vim.highlight.on_yank({ timeout = 200 })
end,
})
@ -61,15 +61,15 @@ au({ 'WinLeave', 'InsertEnter' }, {
-- Autocompletion
au('LspAttach', {
group = group,
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
callback = function(event)
local client = vim.lsp.get_client_by_id(event.data.client_id)
if not client then
return
end
-- Enable native completion
if client:supports_method('textDocument/completion') then
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
end
end,
})

View File

@ -16,7 +16,6 @@ vim.g.loaded_vimballPlugin = 1
vim.g.loaded_matchit = 1
vim.g.loaded_2html_plugin = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_matchparen = 1
vim.g.loaded_tutor_mode_plugin = 1
vim.g.loaded_spellfile_plugin = 1
vim.g.loaded_logipat = 1
@ -87,7 +86,7 @@ vim.opt.undofile = true
vim.opt.swapfile = false
-- Tweaks
vim.opt.updatetime = 1000
vim.opt.updatetime = 50
vim.opt.timeout = true
vim.opt.ttimeout = true
vim.opt.timeoutlen = 500

View File

@ -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,
})