@@ -28,6 +28,7 @@ local M = {
28
28
vault = require (" gp.vault" ), -- handles secrets
29
29
whisper = require (" gp.whisper" ), -- whisper module
30
30
macro = require (" gp.macro" ), -- builder for macro completion
31
+ buffer_state = require (" gp.buffer_state" ), -- buffer state module
31
32
}
32
33
33
34
---- ----------------------------------------------------------------------------
@@ -267,6 +268,23 @@ M.setup = function(opts)
267
268
end ,
268
269
})
269
270
271
+ vim .api .nvim_create_autocmd (" BufEnter" , {
272
+ callback = function (ev )
273
+ local buf = ev .buf
274
+ local context_dir = M .buffer_state .get_key (buf , " context_dir" )
275
+ context_dir = context_dir or M .helpers .find_git_root ()
276
+ if context_dir == " " then
277
+ context_dir = vim .fn .getcwd ()
278
+ end
279
+
280
+ local full_path = vim .fn .fnamemodify (context_dir , " :p" )
281
+ if vim .fn .isdirectory (full_path ) == 1 then
282
+ full_path = vim .fn .resolve (full_path )
283
+ M .buffer_state .set (buf , " context_dir" , full_path )
284
+ end
285
+ end ,
286
+ })
287
+
270
288
if vim .fn .executable (" curl" ) == 0 then
271
289
M .logger .error (" curl is not installed, run :checkhealth gp" )
272
290
end
@@ -695,9 +713,16 @@ M.new_chat = function(params, toggle, system_prompt, agent)
695
713
system_prompt = " "
696
714
end
697
715
716
+ local context_dir = M .buffer_state .get_key (vim .api .nvim_get_current_buf (), " context_dir" )
717
+ context_dir = context_dir or M .helpers .find_git_root ()
718
+ if context_dir == " " then
719
+ context_dir = vim .fn .getcwd ()
720
+ end
721
+ context_dir = " contextDir: " .. context_dir .. " \n "
722
+
698
723
local template = M .render .template (M .config .chat_template or require (" gp.defaults" ).chat_template , {
699
724
[" {{filename}}" ] = string.match (filename , " ([^/]+)$" ),
700
- [" {{optional_headers}}" ] = model .. provider .. system_prompt ,
725
+ [" {{optional_headers}}" ] = model .. provider .. system_prompt .. context_dir ,
701
726
[" {{user_prefix}}" ] = M .config .chat_user_prefix ,
702
727
[" {{respond_shortcut}}" ] = M .config .chat_shortcut_respond .shortcut ,
703
728
[" {{cmd_prefix}}" ] = M .config .cmd_prefix ,
@@ -1065,8 +1090,6 @@ M.chat_header_lines = function(lines)
1065
1090
return lines , 0 , 0
1066
1091
end
1067
1092
1068
- local header_lines = table.concat (vim .list_slice (lines , 0 , header_end + 1 ), " \n " )
1069
-
1070
1093
local help_template = M .render .template (M .defaults .chat_help , {
1071
1094
[" {{user_prefix}}" ] = M .config .chat_user_prefix ,
1072
1095
[" {{respond_shortcut}}" ] = M .config .chat_shortcut_respond .shortcut ,
0 commit comments