From ae3d2d20ee42f68368862aae93104ff5b4531010 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Sun, 26 Oct 2025 05:49:02 +0200 Subject: [PATCH] feat: improve lint logic --- lua/core/events.lua | 8 ++++---- lua/core/options.lua | 3 +-- lua/plugins/language-manager.lua | 28 +++++++++++++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lua/core/events.lua b/lua/core/events.lua index 3a711de..6ce7b18 100644 --- a/lua/core/events.lua +++ b/lua/core/events.lua @@ -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, }) diff --git a/lua/core/options.lua b/lua/core/options.lua index 4c3d5ce..cac91c8 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -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 diff --git a/lua/plugins/language-manager.lua b/lua/plugins/language-manager.lua index 5033c69..76ea47c 100644 --- a/lua/plugins/language-manager.lua +++ b/lua/plugins/language-manager.lua @@ -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, })