feat: load plugin on cmd complete and make completion just work

This commit is contained in:
Folke Lemaitre 2022-11-23 16:08:44 +01:00
parent 4df73f167d
commit 2080694e34
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 17 additions and 5 deletions

View File

@ -110,23 +110,35 @@ function M.setup()
-- commands -- commands
Util.track("loader_commands") Util.track("loader_commands")
for cmd, plugins in pairs(M.loaders.cmd or {}) do for cmd, plugins in pairs(M.loaders.cmd or {}) do
vim.api.nvim_create_user_command(cmd, function(event) local function _load(complete)
vim.api.nvim_del_user_command(cmd) vim.api.nvim_del_user_command(cmd)
Util.track("cmd: " .. cmd) if complete then
M.load(plugins) Util.track("cmd-complete: " .. cmd)
else
Util.track("cmd: " .. cmd)
end
M.load(plugins, { cmd = cmd })
Util.track()
end
vim.api.nvim_create_user_command(cmd, function(event)
_load()
vim.cmd( vim.cmd(
("%s %s%s%s %s"):format( ("%s %s%s%s %s"):format(
event.mods or "", event.mods or "",
event.line1 == event.line2 and "" or event.line1 .. "," .. event.line2, event.line1 == event.line2 and "" or event.line1 .. "," .. event.line2,
cmd, cmd,
event.bang and "!" or "", event.bang and "!" or "",
event.args event.args or ""
) )
) )
Util.track()
end, { end, {
bang = true, bang = true,
nargs = "*", nargs = "*",
complete = function()
_load(true)
-- HACK: trick Neovim to show the newly loaded command completion
vim.api.nvim_input("<space><bs><tab>")
end,
}) })
end end
Util.track() Util.track()