mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-27 19:29:06 +02:00
refactor: moved handler to separate modules
This commit is contained in:
parent
1ae4e0ce9a
commit
b8d8648d28
7 changed files with 320 additions and 228 deletions
45
lua/lazy/core/handler/cmd.lua
Normal file
45
lua/lazy/core/handler/cmd.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
local Util = require("lazy.core.util")
|
||||
local Loader = require("lazy.core.loader")
|
||||
|
||||
---@class LazyCmdHandler:LazyHandler
|
||||
local M = {}
|
||||
|
||||
local function _load(plugin, cmd)
|
||||
vim.api.nvim_del_user_command(cmd)
|
||||
Util.track({ cmd = cmd })
|
||||
Loader.load(plugin, { cmd = cmd })
|
||||
Util.track()
|
||||
end
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
---@param cmd string
|
||||
function M:_add(plugin, cmd)
|
||||
vim.api.nvim_create_user_command(cmd, function(event)
|
||||
_load(plugin, cmd)
|
||||
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 = "*",
|
||||
complete = function()
|
||||
_load(plugin, cmd)
|
||||
-- HACK: trick Neovim to show the newly loaded command completion
|
||||
vim.api.nvim_input("<space><bs><tab>")
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
---@param _plugin LazyPlugin
|
||||
---@param value string
|
||||
function M:_del(_plugin, value)
|
||||
pcall(vim.api.nvim_del_user_command, value)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue