From 15bdbb0f06864ceed557858af51d7c2fff567dbc Mon Sep 17 00:00:00 2001 From: Yuhf7 <77704716+Yuhf7@users.noreply.github.com> Date: Fri, 26 Dec 2025 22:49:28 +0000 Subject: [PATCH] fix(cmd): load plugin when command invoked with args Problem: If a command is set to lazy-load a plugin, running it with arguments won't load the plugin because the wrapper command created by zpack does not accept arguments by default, resulting in `E488: Trailing characters` error. Solution: set `nargs = '*'` so that the wrapper command can accept any number of args and correcly pass them onto the real command once loaded. --- lua/tests/lazy_cmd_test.lua | 24 ++++++++++++++++++++++++ lua/zpack/lazy_trigger/cmd.lua | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lua/tests/lazy_cmd_test.lua b/lua/tests/lazy_cmd_test.lua index 63ea02f..0f54e35 100644 --- a/lua/tests/lazy_cmd_test.lua +++ b/lua/tests/lazy_cmd_test.lua @@ -81,6 +81,30 @@ return function() end) end) + helpers.cleanup_test_env() + end) + helpers.test("plugin loads when command is invoked with args", function() + helpers.setup_test_env() + local state = require('zpack.state') + local loaded = false + + require('zpack').setup({ auto_import = false }) + require('zpack').add({ + 'test/plugin', + cmd = 'TestCommand', + config = function() + loaded = true + end, + }) + + vim.schedule(function() + pcall(vim.cmd, 'TestCommand somearg') + + vim.schedule(function() + helpers.assert_true(loaded, "Plugin should load when command is invoked with args") + end) + end) + helpers.cleanup_test_env() end) end) diff --git a/lua/zpack/lazy_trigger/cmd.lua b/lua/zpack/lazy_trigger/cmd.lua index 3ddc2cc..7cc8141 100644 --- a/lua/zpack/lazy_trigger/cmd.lua +++ b/lua/zpack/lazy_trigger/cmd.lua @@ -37,7 +37,7 @@ M.setup = function(registered_pack_specs) cmd = cmd, args = cmd_args.fargs, }, {}) - end, {}) + end, { nargs = '*' }) end end