fix(extras): better reasons as to why some extras are included in your config.

This commit is contained in:
Folke Lemaitre
2024-06-14 11:13:56 +02:00
parent 6efbdabd1b
commit eeccbbc407
4 changed files with 45 additions and 5 deletions

View File

@ -26,4 +26,13 @@ return {
"neovim/nvim-lspconfig",
dependencies = {},
},
-- dummy import to save core imports
{
import = "foobar",
enabled = function()
LazyVim.plugin.save_core()
return false
end,
},
}

View File

@ -20,8 +20,9 @@ local v = version.major .. "_" .. version.minor
local compat = { "0_9" }
LazyVim.plugin.save_core()
if vim.tbl_contains(compat, v) then
extras[#extras + 1] = "lazyvim.plugins.compat.nvim-" .. v
table.insert(extras, 1, "lazyvim.plugins.compat.nvim-" .. v)
end
table.sort(extras, function(a, b)

View File

@ -250,10 +250,30 @@ end
---@param extra LazyExtra
function X:extra(extra)
if not extra.managed then
self:diagnostic({
message = "Not managed by LazyExtras (config)",
severity = vim.diagnostic.severity.WARN,
})
---@type LazyExtra[]
local parents = {}
for _, x in ipairs(self.extras) do
if x.enabled and vim.tbl_contains(x.imports, extra.module) then
parents[#parents + 1] = x
end
end
if #parents > 0 then
local pp = vim.tbl_map(function(x)
return x.name
end, parents)
self:diagnostic({
message = "Required by " .. table.concat(pp, ", "),
})
elseif vim.tbl_contains(LazyVim.plugin.core_imports, extra.module) then
self:diagnostic({
message = "This extra is included by default",
})
else
self:diagnostic({
message = "Not managed by LazyExtras (config)",
severity = vim.diagnostic.severity.WARN,
})
end
end
extra.row = self.text:row()
local hl = extra.managed and "LazySpecial" or "LazyLocal"

View File

@ -3,6 +3,9 @@ local Plugin = require("lazy.core.plugin")
---@class lazyvim.util.plugin
local M = {}
---@type string[]
M.core_imports = {}
M.lazy_file_events = { "BufReadPost", "BufNewFile", "BufWritePre" }
---@type table<string, string>
@ -32,6 +35,13 @@ M.renames = {
["glepnir/dashboard-nvim"] = "nvimdev/dashboard-nvim",
}
function M.save_core()
if vim.v.vim_did_enter == 1 then
return
end
M.core_imports = vim.deepcopy(require("lazy.core.config").spec.modules)
end
function M.setup()
M.fix_imports()
M.fix_renames()