@@ -603,6 +603,15 @@ _H.find_git_root = function()
603603 return " "
604604end
605605
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
606615-- tries to find an .gp.md file in the root of current git repo
607616--- @return string # returns instructions from the .gp.md file
608617M .repo_instructions = function ()
@@ -628,6 +637,7 @@ M.template_render = function(template, command, selection, filetype, filename)
628637 [" {{selection}}" ] = selection ,
629638 [" {{filetype}}" ] = filetype ,
630639 [" {{filename}}" ] = filename ,
640+ [" {{file_content}}" ] = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false )
631641 }
632642 return _H .template_render (template , key_value_pairs )
633643end
@@ -916,6 +926,8 @@ M.Target = {
916926 append = 1 , -- for appending after the selection, range or the current line
917927 prepend = 2 , -- for prepending before the selection, range or the current line
918928 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
919931
920932 -- for writing into a new buffer
921933 --- @param filetype nil | string # nil = same as the original buffer
@@ -966,11 +978,13 @@ M.prepare_commands = function()
966978 -- rewrite needs custom template
967979 if target == M .Target .rewrite then
968980 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
971984 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
974988 template = M .config .template_prepend
975989 end
976990 end
@@ -2494,6 +2508,7 @@ end
24942508
24952509M .Prompt = function (params , target , prompt , model , template , system_template , whisper )
24962510 -- enew, new, vnew, tabnew should be resolved into table
2511+ print (template )
24972512 if type (target ) == " function" then
24982513 target = target ()
24992514 end
@@ -2665,7 +2680,6 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
26652680
26662681 local user_prompt = M .template_render (template , command , selection , filetype , filename )
26672682 table.insert (messages , { role = " user" , content = user_prompt })
2668-
26692683 -- cancel possible visual mode before calling the model
26702684 M ._H .feedkeys (" <esc>" , " xn" )
26712685
@@ -2680,13 +2694,25 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
26802694 vim .api .nvim_buf_set_lines (buf , start_line - 1 , end_line - 1 , false , {})
26812695 -- prepare handler
26822696 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 )
26832702 elseif target == M .Target .append then
26842703 -- move cursor to the end of the selection
26852704 vim .api .nvim_win_set_cursor (0 , { end_line , 0 })
26862705 -- put newline after selection
26872706 vim .api .nvim_put ({ " " }, " l" , true , true )
26882707 -- prepare handler
26892708 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 )
26902716 elseif target == M .Target .prepend then
26912717 -- move cursor to the start of the selection
26922718 vim .api .nvim_win_set_cursor (0 , { start_line , 0 })
0 commit comments