refactor: simplified handler code

This commit is contained in:
Folke Lemaitre 2022-12-16 09:13:08 +01:00
parent 17d1653b4a
commit ecf03a6892
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 58 additions and 91 deletions

View file

@ -4,18 +4,17 @@ local Loader = require("lazy.core.loader")
---@class LazyCmdHandler:LazyHandler
local M = {}
local function _load(plugin, cmd)
function M:_load(cmd)
vim.api.nvim_del_user_command(cmd)
Util.track({ cmd = cmd })
Loader.load(plugin, { cmd = cmd })
Loader.load(self.active[cmd], { cmd = cmd })
Util.track()
end
---@param plugin LazyPlugin
---@param cmd string
function M:_add(plugin, cmd)
function M:_add(cmd)
vim.api.nvim_create_user_command(cmd, function(event)
_load(plugin, cmd)
self:_load(cmd)
vim.cmd(
("%s %s%s%s %s"):format(
event.mods or "",
@ -29,7 +28,7 @@ function M:_add(plugin, cmd)
bang = true,
nargs = "*",
complete = function(_, line)
_load(plugin, cmd)
self:_load(cmd)
-- NOTE: return the newly loaded command completion
return vim.fn.getcompletion(line, "cmdline")
end,