From 11dc038c506d019372b73f00f4f83758dbb5bd65 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Sat, 4 Nov 2023 07:53:36 +0000 Subject: [PATCH] refactor(vim): update when the linters run Move the linters to run on BufReadPost instead of BufEnter. This was running the linters whenever a buffer opened, when jumping around quickly with and this would cause the linters to run a lot when there were not needed. Now were are only running them once when the buffer is read from disk. Adds a custom function that will add cspell to all of the filetypes. This will then only run `try_lint` once to improve the performance. Now neoformat has gone fully async. When calling `try_lint` one after the other, the first processes were getting canceled. --- site-modules/core/files/vim/plugin/lint.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/site-modules/core/files/vim/plugin/lint.lua b/site-modules/core/files/vim/plugin/lint.lua index 5844b13..a6a5705 100644 --- a/site-modules/core/files/vim/plugin/lint.lua +++ b/site-modules/core/files/vim/plugin/lint.lua @@ -73,22 +73,30 @@ lint.linters_by_ft = { scss = {'stylelint'}, } +local file_types_map = { [ "" ] = false, qf = false, ivy = false } -- Lint code with nvim-lint on save. This will lint all filetypes with cspell -- and then any other filetypes will be linted per the config. local lint_auto_command_group = vim.api.nvim_create_augroup("aa_lint", { clear = true }) -vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost" }, { + +vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost" }, { group = lint_auto_command_group, desc = "Lint the buffer", pattern = "*", callback = function() - -- Only try and run spell checking on buffers that have a filetype. This is - -- mainly to disable spell checking in vim lsp popup buffers. - if vim.bo.filetype ~= "" then - lint.try_lint('cspell') + local linters = lint._resolve_linter_by_ft(vim.bo.filetype) + local should_lint = file_types_map[vim.bo.filetype] + if should_lint == nil then + should_lint = true end - lint.try_lint() + -- Only try and run spell checking on buffers that have a filetype. This is + -- mainly to disable spell checking in vim lsp popup buffers. + if should_lint then + table.insert(linters, 'cspell') + end + + lint.try_lint(linters) end, })