Skip to content

Commit 6a18bb3

Browse files
committed
fix(lint): give the plugin-loading buffer its initial lint
The lint autocmd lints on every event except FileType, which is resolve-only: lazy.nvim replays the plugin-loading buffer's BufReadPost before ftdetect, so that replayed lint sees ft="" and no-ops, and FileType only resolves the real ft. That one buffer got its linters resolved but never linted until the next InsertLeave/save. Register a buffer-scoped, one-shot FileType autocmd for the load buffer only when its ft is still "" at config time. For a BufReadPost load the timeline is replay-noop + resolve-only FileType + this one-shot = exactly one lint. For a BufWritePost load (ft already set) the replayed trigger event lints via the main handler, so the guard skips registration to avoid a double lint. Placed in the NvimLint group so a config re-source's clear=true wipes a stale one-shot instead of stacking a second copy.
1 parent 9ba25cb commit 6a18bb3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

lua/modules/configs/completion/nvim-lint.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,29 @@ return function()
422422
})
423423
vim.defer_fn(fire, SWEEP_FALLBACK_MS)
424424
end, SWEEP_DELAY_MS)
425+
426+
-- The buffer that loaded this plugin (lazy triggers: BufReadPost / BufWritePost)
427+
-- can slip through the initial lint in ONE case: a BufReadPost load, where
428+
-- lazy.nvim replays BufReadPost BEFORE ftdetect (ft="", a no-op lint) and the
429+
-- FileType handler above is resolve-only — so this buffer alone would wait for
430+
-- the next InsertLeave/save. When ft is ALREADY set at config time (a
431+
-- BufWritePost load, or any ft-set load), the replayed trigger event lints via
432+
-- the main handler, so NO help is needed — registering a one-shot there would
433+
-- double-lint (the round-1 O1 defect). Hence: only the ft="" case, and only
434+
-- once, in the NvimLint group so a config re-source's clear=true wipes a stale
435+
-- copy instead of stacking.
436+
local load_buf = vim.api.nvim_get_current_buf()
437+
if vim.bo[load_buf].filetype == "" then
438+
vim.api.nvim_create_autocmd("FileType", {
439+
group = "NvimLint",
440+
buffer = load_buf,
441+
once = true,
442+
callback = function()
443+
ensure_resolved(vim.bo[load_buf].filetype)
444+
vim.api.nvim_buf_call(load_buf, function()
445+
lint.try_lint(nil, { ignore_errors = true })
446+
end)
447+
end,
448+
})
449+
end
425450
end

0 commit comments

Comments
 (0)