@@ -628,6 +628,7 @@ M.template_render = function(template, command, selection, filetype, filename)
628
628
[" {{selection}}" ] = selection ,
629
629
[" {{filetype}}" ] = filetype ,
630
630
[" {{filename}}" ] = filename ,
631
+ [" {{file_content}}" ] = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false )
631
632
}
632
633
return _H .template_render (template , key_value_pairs )
633
634
end
@@ -916,6 +917,9 @@ M.Target = {
916
917
append = 1 , -- for appending after the selection, range or the current line
917
918
prepend = 2 , -- for prepending before the selection, range or the current line
918
919
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
919
923
920
924
-- for writing into a new buffer
921
925
--- @param filetype nil | string # nil = same as the original buffer
@@ -966,12 +970,16 @@ M.prepare_commands = function()
966
970
-- rewrite needs custom template
967
971
if target == M .Target .rewrite then
968
972
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
971
976
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
974
980
template = M .config .template_prepend
981
+ elseif target == M .Target .prependWithFile then
982
+ template = M .config .template_prepend_with_file
975
983
end
976
984
end
977
985
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
2684
2692
vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
2685
2693
-- prepare handler
2686
2694
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 )
2687
2700
elseif target == M .Target .append then
2688
2701
-- move cursor to the end of the selection
2689
2702
vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
2690
2703
-- put newline after selection
2691
2704
vim .api .nvim_put ({ " " }, " l" , true , true )
2692
2705
-- prepare handler
2693
2706
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 )
2694
2714
elseif target == M .Target .prepend then
2695
2715
-- move cursor to the start of the selection
2696
2716
vim .api .nvim_win_set_cursor (0 , { start_line , 0 })
2697
2717
-- put newline before selection
2698
2718
vim .api .nvim_put ({ " " }, " l" , false , true )
2699
2719
-- prepare handler
2700
2720
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 )
2701
2728
elseif target == M .Target .popup then
2702
2729
M ._toggle_close (M ._toggle_kind .popup )
2703
2730
-- create a new buffer
0 commit comments