@@ -334,6 +334,7 @@ function M.debug_session()
334334 debug_helper .debug_session ()
335335end
336336
337+ --- @type fun (): Promise<void>
337338M .initialize = Promise .async (function ()
338339 local id = require (' opencode.id' )
339340
@@ -368,8 +369,8 @@ function M.agent_build()
368369 require (' opencode.core' ).switch_to_mode (' build' )
369370end
370371
371- function M .select_agent ()
372- local modes = config_file .get_opencode_agents ()
372+ M .select_agent = Promise . async ( function ()
373+ local modes = config_file .get_opencode_agents (): await ()
373374 vim .ui .select (modes , {
374375 prompt = ' Select mode:' ,
375376 }, function (selection )
@@ -379,10 +380,10 @@ function M.select_agent()
379380
380381 require (' opencode.core' ).switch_to_mode (selection )
381382 end )
382- end
383+ end )
383384
384- function M .switch_mode ()
385- local modes = config_file .get_opencode_agents () --[[ @as string[] ]]
385+ M .switch_mode = Promise . async ( function ()
386+ local modes = config_file .get_opencode_agents (): await () --[[ @as string[] ]]
386387
387388 local current_index = util .index_of (modes , state .current_mode )
388389
@@ -394,7 +395,7 @@ function M.switch_mode()
394395 local next_index = (current_index % # modes ) + 1
395396
396397 require (' opencode.core' ).switch_to_mode (modes [next_index ])
397- end
398+ end )
398399
399400function M .with_header (lines , show_welcome )
400401 show_welcome = show_welcome or show_welcome
@@ -506,7 +507,7 @@ M.mcp = Promise.async(function()
506507end )
507508
508509function M .commands_list ()
509- local commands = config_file .get_user_commands ():await ()
510+ local commands = config_file .get_user_commands ():wait ()
510511 if not commands then
511512 vim .notify (' No user commands found. Please check your opencode config file.' , vim .log .levels .WARN )
512513 return
@@ -566,7 +567,7 @@ M.run_user_command = Promise.async(function(name, args)
566567 require (' opencode.history' ).write (' /' .. name .. ' ' .. table.concat (args or {}, ' ' ))
567568 end )
568569 end )
569- end )
570+ end ) --[[ @as Promise<void> ]]
570571end )
571572
572573--- Compacts the current session by removing unnecessary data.
@@ -754,7 +755,7 @@ M.rename_session = Promise.async(function(current_session, new_title)
754755 vim .notify (' Failed to rename session: ' .. vim .inspect (err ), vim .log .levels .ERROR )
755756 end )
756757 end )
757- :and_then (function ()
758+ :and_then (Promise . async ( function ()
758759 current_session .title = title
759760 if state .active_session and state .active_session .id == current_session .id then
760761 local session_obj = session .get_by_id (current_session .id ):await ()
@@ -764,7 +765,7 @@ M.rename_session = Promise.async(function(current_session, new_title)
764765 end
765766 end
766767 promise :resolve (current_session )
767- end )
768+ end ))
768769 end
769770
770771 if new_title and new_title ~= ' ' then
@@ -967,18 +968,20 @@ M.commands = {
967968 fn = function (args )
968969 local subcmd = args [1 ]
969970 if subcmd == ' new' then
970- local title = table.concat (vim .list_slice (args , 2 ), ' ' )
971- if title and title ~= ' ' then
972- local new_session = core .create_new_session (title )
973- if not new_session then
974- vim .notify (' Failed to create new session' , vim .log .levels .ERROR )
975- return
971+ Promise .spawn (function ()
972+ local title = table.concat (vim .list_slice (args , 2 ), ' ' )
973+ if title and title ~= ' ' then
974+ local new_session = core .create_new_session (title ):await ()
975+ if not new_session then
976+ vim .notify (' Failed to create new session' , vim .log .levels .ERROR )
977+ return
978+ end
979+ state .active_session = new_session
980+ M .open_input ()
981+ else
982+ M .open_input_new_session ()
976983 end
977- state .active_session = new_session :await ()
978- M .open_input ()
979- else
980- M .open_input_new_session ()
981- end
984+ end )
982985 elseif subcmd == ' select' then
983986 M .select_session ()
984987 elseif subcmd == ' child' then
@@ -1230,6 +1233,7 @@ M.slash_commands_map = {
12301233 [' /timeline' ] = { fn = M .timeline , desc = ' Open timeline picker' },
12311234 [' /undo' ] = { fn = M .undo , desc = ' Undo last action' },
12321235 [' /unshare' ] = { fn = M .unshare , desc = ' Unshare current session' },
1236+ [' /rename' ] = { fn = M .rename_session , desc = ' Rename current session' },
12331237}
12341238
12351239M .legacy_command_map = {
0 commit comments