2022-12-05 21:45:50 +08:00
|
|
|
local Util = require("lazy.core.util")
|
|
|
|
local Loader = require("lazy.core.loader")
|
|
|
|
|
|
|
|
---@class LazyCmdHandler:LazyHandler
|
|
|
|
local M = {}
|
|
|
|
|
2022-12-16 16:13:08 +08:00
|
|
|
function M:_load(cmd)
|
2022-12-05 21:45:50 +08:00
|
|
|
vim.api.nvim_del_user_command(cmd)
|
|
|
|
Util.track({ cmd = cmd })
|
2022-12-16 16:13:08 +08:00
|
|
|
Loader.load(self.active[cmd], { cmd = cmd })
|
2022-12-05 21:45:50 +08:00
|
|
|
Util.track()
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param cmd string
|
2022-12-16 16:13:08 +08:00
|
|
|
function M:_add(cmd)
|
2022-12-05 21:45:50 +08:00
|
|
|
vim.api.nvim_create_user_command(cmd, function(event)
|
2022-12-16 16:13:08 +08:00
|
|
|
self:_load(cmd)
|
2022-12-05 21:45:50 +08:00
|
|
|
vim.cmd(
|
|
|
|
("%s %s%s%s %s"):format(
|
|
|
|
event.mods or "",
|
|
|
|
event.line1 == event.line2 and "" or event.line1 .. "," .. event.line2,
|
|
|
|
cmd,
|
|
|
|
event.bang and "!" or "",
|
|
|
|
event.args or ""
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end, {
|
|
|
|
bang = true,
|
|
|
|
nargs = "*",
|
2022-12-13 16:48:17 +08:00
|
|
|
complete = function(_, line)
|
2022-12-16 16:13:08 +08:00
|
|
|
self:_load(cmd)
|
2022-12-13 16:48:17 +08:00
|
|
|
-- NOTE: return the newly loaded command completion
|
|
|
|
return vim.fn.getcompletion(line, "cmdline")
|
2022-12-05 21:45:50 +08:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param _plugin LazyPlugin
|
|
|
|
---@param value string
|
|
|
|
function M:_del(_plugin, value)
|
|
|
|
pcall(vim.api.nvim_del_user_command, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|