@@ -3,6 +3,7 @@ local util = require('opencode.util')
33local session = require (' opencode.session' )
44local config_file = require (' opencode.config_file' )
55local state = require (' opencode.state' )
6+ local quick_chat = require (' opencode.quick_chat' )
67
78local input_window = require (' opencode.ui.input_window' )
89local ui = require (' opencode.ui.ui' )
@@ -107,6 +108,15 @@ function M.select_history()
107108 require (' opencode.ui.history_picker' ).pick ()
108109end
109110
111+ function M .quick_chat (message , range )
112+ local options = {}
113+ if type (message ) == ' table' then
114+ message = table.concat (message , ' ' )
115+ end
116+
117+ return quick_chat .quick_chat (message , options , range )
118+ end
119+
110120function M .toggle_pane ()
111121 return core .open ({ new_session = false , focus = ' output' }):and_then (function ()
112122 ui .toggle_pane ()
@@ -966,6 +976,14 @@ M.commands = {
966976 fn = M .toggle_zoom ,
967977 },
968978
979+ quick_chat = {
980+ desc = ' Quick chat with current context' ,
981+ fn = M .quick_chat ,
982+ range = true , -- Enable range support for visual selections
983+ nargs = ' +' , -- Allow multiple arguments
984+ complete = false , -- No completion for custom messages
985+ },
986+
969987 swap = {
970988 desc = ' Swap pane position left/right' ,
971989 fn = M .swap_position ,
@@ -1300,6 +1318,14 @@ M.legacy_command_map = {
13001318
13011319function M .route_command (opts )
13021320 local args = vim .split (opts .args or ' ' , ' %s+' , { trimempty = true })
1321+ local range = nil
1322+
1323+ if opts .range and opts .range > 0 then
1324+ range = {
1325+ start = opts .line1 ,
1326+ stop = opts .line2 ,
1327+ }
1328+ end
13031329
13041330 if # args == 0 then
13051331 M .toggle ()
@@ -1310,7 +1336,7 @@ function M.route_command(opts)
13101336 local subcmd_def = M .commands [subcommand ]
13111337
13121338 if subcmd_def and subcmd_def .fn then
1313- subcmd_def .fn (vim .list_slice (args , 2 ))
1339+ subcmd_def .fn (vim .list_slice (args , 2 ), range )
13141340 else
13151341 vim .notify (' Unknown subcommand: ' .. subcommand , vim .log .levels .ERROR )
13161342 end
@@ -1404,6 +1430,7 @@ function M.setup()
14041430 vim .api .nvim_create_user_command (' Opencode' , M .route_command , {
14051431 desc = ' Opencode.nvim main command with nested subcommands' ,
14061432 nargs = ' *' ,
1433+ range = true , -- Enable range support
14071434 complete = M .complete_command ,
14081435 })
14091436
0 commit comments