@@ -2,6 +2,7 @@ local M = {}
22
33local config = require (" opencode.config" )
44local terminal = require (" opencode.terminal" )
5+ local placeholders = require (" opencode.placeholders" )
56
67-- @param opts opencode.Config
78function M .setup (opts )
1516function M .ask (opts )
1617 local mode = vim .fn .mode ()
1718
18- local function replace_file_placeholder (input )
19- -- Replace @file with the current file path
20- if input :find (" @file" ) then
21- local relative_path = vim .fn .expand (" %:." )
22- if relative_path == " " then
23- vim .notify (" No file is currently open." , vim .log .levels .WARN )
24- return input
25- end
26- return input :gsub (" @file" , " @" .. relative_path )
27- end
28- return input
29- end
30-
3119 -- Visual mode handling
3220 if vim .tbl_contains ({ " v" , " V" , " " }, mode ) then
3321 local lines = vim .fn .getregion (vim .fn .getpos (" v" ), vim .fn .getpos (" ." ), { type = mode })
@@ -36,7 +24,7 @@ function M.ask(opts)
3624 vim .ui .input ({ prompt = " Add a prompt to your selection (empty to skip):" }, function (input )
3725 if input ~= nil then
3826 if input ~= " " then
39- selected_text = selected_text .. " \n\n " .. replace_file_placeholder (input )
27+ selected_text = selected_text .. " \n\n " .. placeholders . replace_file (input )
4028 end
4129 terminal .send (selected_text , opts or {}, true )
4230 end
@@ -45,7 +33,7 @@ function M.ask(opts)
4533 -- Normal mode handling
4634 vim .ui .input ({ prompt = " Ask opencode: " }, function (input )
4735 if input then
48- terminal .send (replace_file_placeholder (input ), opts or {})
36+ terminal .send (placeholders . replace_file (input ), opts or {})
4937 end
5038 end )
5139 end
0 commit comments