@@ -628,6 +628,7 @@ M.template_render = function(template, command, selection, filetype, filename)
628628 [" {{selection}}" ] = selection ,
629629 [" {{filetype}}" ] = filetype ,
630630 [" {{filename}}" ] = filename ,
631+ [" {{file_content}}" ] = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false )
631632 }
632633 return _H .template_render (template , key_value_pairs )
633634end
@@ -916,6 +917,9 @@ M.Target = {
916917 append = 1 , -- for appending after the selection, range or the current line
917918 prepend = 2 , -- for prepending before the selection, range or the current line
918919 popup = 3 , -- for writing into the popup window
920+ rewriteWithFile = 4 , -- for replacing the selection, range or the current line with the full file as context
921+ appendWithFile = 5 , -- for appending after the selection, range or the current line with the full file as context
922+ prependWithFile = 6 , -- for appending after the selection, range or the current line with the full file as context
919923
920924 -- for writing into a new buffer
921925 --- @param filetype nil | string # nil = same as the original buffer
@@ -966,12 +970,16 @@ M.prepare_commands = function()
966970 -- rewrite needs custom template
967971 if target == M .Target .rewrite then
968972 template = M .config .template_rewrite
969- end
970- if target == M .Target .append then
973+ elseif target == M .Target .rewriteWithFile then
974+ template = M .config .template_rewrite_with_file
975+ elseif target == M .Target .append then
971976 template = M .config .template_append
972- end
973- if target == M .Target .prepend then
977+ elseif target == M .Target .appendWithFile then
978+ template = M .config .template_append_with_file
979+ elseif target == M .Target .prepend then
974980 template = M .config .template_prepend
981+ elseif target == M .Target .prependWithFile then
982+ template = M .config .template_prepend_with_file
975983 end
976984 end
977985 M .Prompt (params , target , agent .cmd_prefix , agent .model , template , agent .system_prompt , whisper )
@@ -2684,20 +2692,39 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
26842692 vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
26852693 -- prepare handler
26862694 handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
2695+ elseif target == M .Target .rewriteWithFile then
2696+ -- delete selection
2697+ vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
2698+ -- prepare handler
2699+ handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
26872700 elseif target == M .Target .append then
26882701 -- move cursor to the end of the selection
26892702 vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
26902703 -- put newline after selection
26912704 vim .api .nvim_put ({ " " }, " l" , true , true )
26922705 -- prepare handler
26932706 handler = M .create_handler (buf , win , end_line , true , prefix , cursor )
2707+ elseif target == M .Target .appendWithFile then
2708+ -- move cursor to the end of the selection
2709+ vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
2710+ -- put newline after selection
2711+ vim .api .nvim_put ({ " " }, " l" , true , true )
2712+ -- prepare handler
2713+ handler = M .create_handler (buf , win , end_line , true , prefix , cursor )
26942714 elseif target == M .Target .prepend then
26952715 -- move cursor to the start of the selection
26962716 vim .api .nvim_win_set_cursor (0 , { start_line , 0 })
26972717 -- put newline before selection
26982718 vim .api .nvim_put ({ " " }, " l" , false , true )
26992719 -- prepare handler
27002720 handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
2721+ elseif target == M .Target .prependWithFile then
2722+ -- move cursor to the start of the selection
2723+ vim .api .nvim_win_set_cursor (0 , { start_line , 0 })
2724+ -- put newline before selection
2725+ vim .api .nvim_put ({ " " }, " l" , false , true )
2726+ -- prepare handler
2727+ handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
27012728 elseif target == M .Target .popup then
27022729 M ._toggle_close (M ._toggle_kind .popup )
27032730 -- create a new buffer
0 commit comments