Skip to content

Commit af0f425

Browse files
feat(nvim-lint): make autocmd events configurable (#1245)
* feat(nvim-lint): make autocmd events configurable * Move nvim-lint autocommand to AstroCore --------- Co-authored-by: Micah Halter <[email protected]>
1 parent 033dde8 commit af0f425

File tree

1 file changed

+27
-14
lines changed
  • lua/astrocommunity/lsp/nvim-lint

1 file changed

+27
-14
lines changed

lua/astrocommunity/lsp/nvim-lint/init.lua

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1+
local lint -- cache for the nvim-lint package
12
---@type LazySpec
23
return {
34
"mfussenegger/nvim-lint",
45
event = "User AstroFile",
56
dependencies = { "williamboman/mason.nvim" },
67
specs = {
78
{ "jay-babu/mason-null-ls.nvim", optional = true, opts = { methods = { diagnostics = false } } },
9+
{
10+
"AstroNvim/astrocore",
11+
---@param opts AstroCoreOpts
12+
opts = function(_, opts)
13+
local timer = (vim.uv or vim.loop).new_timer()
14+
if not opts.autocmds then opts.autocmds = {} end
15+
opts.autocmds.auto_lint = {
16+
{
17+
event = { "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" },
18+
desc = "Automatically lint with nvim-lint",
19+
callback = function()
20+
-- only run autocommand when nvim-lint is loaded
21+
if lint then
22+
timer:start(100, 0, function()
23+
timer:stop()
24+
vim.schedule(lint.try_lint)
25+
end)
26+
end
27+
end,
28+
},
29+
}
30+
end,
31+
},
832
},
933
opts = {},
1034
config = function(_, opts)
11-
local lint, astrocore = require "lint", require "astrocore"
12-
35+
local astrocore = require "astrocore"
36+
lint = require "lint"
1337
lint.linters_by_ft = opts.linters_by_ft or {}
1438
for name, linter in pairs(opts.linters or {}) do
1539
local base = lint.linters[name]
@@ -39,17 +63,6 @@ return {
3963
return linters
4064
end)
4165

42-
lint.try_lint() -- start linter immediately
43-
local timer = vim.loop.new_timer()
44-
vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, {
45-
group = vim.api.nvim_create_augroup("auto_lint", { clear = true }),
46-
desc = "Automatically try linting",
47-
callback = function()
48-
timer:start(100, 0, function()
49-
timer:stop()
50-
vim.schedule(lint.try_lint)
51-
end)
52-
end,
53-
})
66+
lint.try_lint()
5467
end,
5568
}

0 commit comments

Comments
 (0)