feat(config): show a warning when lazy.nvim imports order is incorrect

This commit is contained in:
Folke Lemaitre 2025-02-08 12:47:41 +01:00
parent 597cd8ffa3
commit 83988ea46e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -206,6 +206,26 @@ function M.setup(opts)
"desc",
"vscode",
})
-- Check lazy.nvim import order
local imports = require("lazy.core.config").spec.modules
local function find(pat, last)
for i = last and #imports or 1, last and 1 or #imports, last and -1 or 1 do
if imports[i]:find(pat) then
return i
end
end
end
local lazyvim_plugins = find("^lazyvim%.plugins$")
local extras = find("^lazyvim%.plugins%.extras%.", true) or lazyvim_plugins
local plugins = find("^plugins$") or math.huge
if lazyvim_plugins ~= 1 or extras > plugins then
vim.notify(
"The order of your `lazy.nvim` imports is incorrect:\n- `lazyvim.plugins` should be first\n- followed by any `lazyvim.plugins.extras`\n- and finally your own `plugins`",
"warn",
{ title = "LazyVim" }
)
end
end,
})