mirror of https://github.com/folke/lazy.nvim.git
feat: load plugin on cmd complete and make completion just work
This commit is contained in:
parent
4df73f167d
commit
2080694e34
|
@ -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)
|
||||||
|
if complete then
|
||||||
|
Util.track("cmd-complete: " .. cmd)
|
||||||
|
else
|
||||||
Util.track("cmd: " .. cmd)
|
Util.track("cmd: " .. cmd)
|
||||||
M.load(plugins)
|
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()
|
||||||
|
|
Loading…
Reference in New Issue