mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
feat(util): inject module
This commit is contained in:
parent
7bbd48caa0
commit
d6bc320f20
4 changed files with 33 additions and 14 deletions
|
@ -210,9 +210,7 @@ function M.init()
|
|||
-- after installing missing plugins
|
||||
M.load("options")
|
||||
|
||||
Util.plugin.fix_imports()
|
||||
Util.plugin.fix_renames()
|
||||
Util.plugin.lazy_file()
|
||||
Util.plugin.setup()
|
||||
M.json.load()
|
||||
end
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ local LazyUtil = require("lazy.core.util")
|
|||
---@field format lazyvim.util.format
|
||||
---@field plugin lazyvim.util.plugin
|
||||
---@field extras lazyvim.util.extras
|
||||
---@field inject lazyvim.util.inject
|
||||
local M = {}
|
||||
|
||||
---@type table<string, string|string[]>
|
||||
|
|
20
lua/lazyvim/util/inject.lua
Normal file
20
lua/lazyvim/util/inject.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
---@class lazyvim.util.inject
|
||||
local M = {}
|
||||
|
||||
---@generic A: any
|
||||
---@generic B: any
|
||||
---@generic C: any
|
||||
---@generic F: function
|
||||
---@param fn F|fun(a:A, b:B, c:C)
|
||||
---@param wrapper fun(a:A, b:B, c:C): boolean?
|
||||
---@return F
|
||||
function M.args(fn, wrapper)
|
||||
return function(...)
|
||||
if wrapper(...) == false then
|
||||
return
|
||||
end
|
||||
return fn(...)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -21,6 +21,12 @@ M.renames = {
|
|||
["null-ls.nvim"] = "none-ls.nvim",
|
||||
}
|
||||
|
||||
function M.setup()
|
||||
M.fix_imports()
|
||||
M.fix_renames()
|
||||
M.lazy_file()
|
||||
end
|
||||
|
||||
-- Properly load file based plugins without blocking the UI
|
||||
function M.lazy_file()
|
||||
M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0
|
||||
|
@ -86,23 +92,18 @@ function M.lazy_file()
|
|||
end
|
||||
|
||||
function M.fix_imports()
|
||||
local import = Plugin.Spec.import
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function Plugin.Spec:import(spec)
|
||||
Plugin.Spec.import = Util.inject.args(Plugin.Spec.import, function(_, spec)
|
||||
local dep = M.deprecated_extras[spec and spec.import]
|
||||
if dep then
|
||||
dep = dep .. "\n" .. "Please remove the extra to hide this warning."
|
||||
Util.warn(dep, { title = "LazyVim", once = true, stacktrace = true, stacklevel = 6 })
|
||||
return
|
||||
end
|
||||
return import(self, spec)
|
||||
return false
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function M.fix_renames()
|
||||
local add = Plugin.Spec.add
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
Plugin.Spec.add = function(self, plugin, ...)
|
||||
Plugin.Spec.add = Util.inject.args(Plugin.Spec.add, function(self, plugin)
|
||||
if type(plugin) == "table" then
|
||||
if M.renames[plugin[1]] then
|
||||
Util.warn(
|
||||
|
@ -116,8 +117,7 @@ function M.fix_renames()
|
|||
plugin[1] = M.renames[plugin[1]]
|
||||
end
|
||||
end
|
||||
return add(self, plugin, ...)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue