@@ -373,13 +373,16 @@ function M.mcp()
373373 ui .render_lines (msg )
374374end
375375
376- function M .run_user_command (name )
376+ --- Runs a user-defined command by name.
377+ --- @param name string The name of the user command to run.
378+ --- @param args ? string[] Additional arguments to pass to the command.
379+ function M .run_user_command (name , args )
377380 M .open_input ()
378381
379382 ui .render_output (true )
380383 state .api_client :send_command (state .active_session .id , {
381384 command = name ,
382- arguments = ' ' ,
385+ arguments = table.concat ( args or {}, ' ' ) ,
383386 })
384387end
385388
@@ -874,12 +877,13 @@ M.commands = {
874877 name = ' OpencodeRunUserCommand' ,
875878 desc = ' Run a user-defined Opencode command by name' ,
876879 fn = function (opts )
877- local name = opts .args and opts .args :match (' ^%s*(%S+)' )
880+ local parts = vim .split (opts .args or ' ' , ' %s+' )
881+ local name = parts [1 ]
878882 if not name or name == ' ' then
879883 vim .notify (' User command name required. Usage: :OpencodeRunUserCommand <name>' , vim .log .levels .ERROR )
880884 return
881885 end
882- M .run_user_command (name )
886+ M .run_user_command (name , vim . list_slice ( parts , 2 ) )
883887 end ,
884888 args = true ,
885889 },
@@ -974,6 +978,7 @@ M.commands = {
974978 },
975979}
976980
981+ --- @return OpencodeSlashCommand[]
977982function M .get_slash_commands ()
978983 local commands = vim .tbl_filter (function (cmd )
979984 return cmd .slash_cmd and cmd .slash_cmd ~= ' '
@@ -985,8 +990,8 @@ function M.get_slash_commands()
985990 table.insert (commands , {
986991 slash_cmd = ' /' .. name ,
987992 desc = ' Run user command: ' .. name ,
988- fn = function ()
989- M .commands . run_user_command . fn ({ args = name } )
993+ fn = function (args )
994+ M .run_user_command ( name , args )
990995 end ,
991996 })
992997 end
0 commit comments