@@ -603,6 +603,15 @@ _H.find_git_root = function()
603
603
return " "
604
604
end
605
605
606
+ _H .repo_instruct_file = function ()
607
+ local git_root = _H .find_git_root ()
608
+
609
+ if git_root == " " then
610
+ return " "
611
+ end
612
+
613
+ return git_root .. " /.gp.md"
614
+ end
606
615
-- tries to find an .gp.md file in the root of current git repo
607
616
--- @return string # returns instructions from the .gp.md file
608
617
M .repo_instructions = function ()
@@ -628,6 +637,7 @@ M.template_render = function(template, command, selection, filetype, filename)
628
637
[" {{selection}}" ] = selection ,
629
638
[" {{filetype}}" ] = filetype ,
630
639
[" {{filename}}" ] = filename ,
640
+ [" {{file_content}}" ] = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false )
631
641
}
632
642
return _H .template_render (template , key_value_pairs )
633
643
end
@@ -916,6 +926,8 @@ M.Target = {
916
926
append = 1 , -- for appending after the selection, range or the current line
917
927
prepend = 2 , -- for prepending before the selection, range or the current line
918
928
popup = 3 , -- for writing into the popup window
929
+ rewriteWithFile = 4 , -- for replacing the selection, range or the current line with the full file as context
930
+ appendWithFile = 5 , -- for appending after the selection, range or the current line with the full file as context
919
931
920
932
-- for writing into a new buffer
921
933
--- @param filetype nil | string # nil = same as the original buffer
@@ -966,11 +978,13 @@ M.prepare_commands = function()
966
978
-- rewrite needs custom template
967
979
if target == M .Target .rewrite then
968
980
template = M .config .template_rewrite
969
- end
970
- if target == M .Target .append then
981
+ elseif target == M .Target .rewriteWithFile then
982
+ template = M .config .template_rewrite_with_file
983
+ elseif target == M .Target .append then
971
984
template = M .config .template_append
972
- end
973
- if target == M .Target .prepend then
985
+ elseif target == M .Target .appendWithFile then
986
+ template = M .config .template_append_with_file
987
+ elseif target == M .Target .prepend then
974
988
template = M .config .template_prepend
975
989
end
976
990
end
@@ -2494,6 +2508,7 @@ end
2494
2508
2495
2509
M .Prompt = function (params , target , prompt , model , template , system_template , whisper )
2496
2510
-- enew, new, vnew, tabnew should be resolved into table
2511
+ print (template )
2497
2512
if type (target ) == " function" then
2498
2513
target = target ()
2499
2514
end
@@ -2665,7 +2680,6 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
2665
2680
2666
2681
local user_prompt = M .template_render (template , command , selection , filetype , filename )
2667
2682
table.insert (messages , { role = " user" , content = user_prompt })
2668
-
2669
2683
-- cancel possible visual mode before calling the model
2670
2684
M ._H .feedkeys (" <esc>" , " xn" )
2671
2685
@@ -2680,13 +2694,25 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
2680
2694
vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
2681
2695
-- prepare handler
2682
2696
handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
2697
+ elseif target == M .Target .rewriteWithFile then
2698
+ -- delete selection
2699
+ vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
2700
+ -- prepare handler
2701
+ handler = M .create_handler (buf , win , start_line - 1 , true , prefix , cursor )
2683
2702
elseif target == M .Target .append then
2684
2703
-- move cursor to the end of the selection
2685
2704
vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
2686
2705
-- put newline after selection
2687
2706
vim .api .nvim_put ({ " " }, " l" , true , true )
2688
2707
-- prepare handler
2689
2708
handler = M .create_handler (buf , win , end_line , true , prefix , cursor )
2709
+ elseif target == M .Target .appendWithFile then
2710
+ -- move cursor to the end of the selection
2711
+ vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
2712
+ -- put newline after selection
2713
+ vim .api .nvim_put ({ " " }, " l" , true , true )
2714
+ -- prepare handler
2715
+ handler = M .create_handler (buf , win , end_line , true , prefix , cursor )
2690
2716
elseif target == M .Target .prepend then
2691
2717
-- move cursor to the start of the selection
2692
2718
vim .api .nvim_win_set_cursor (0 , { start_line , 0 })
0 commit comments