From cfbd81294845a8a0a52480b1ec1e3eca9ab42926 Mon Sep 17 00:00:00 2001 From: koyae Date: Wed, 19 Feb 2025 23:22:29 -0700 Subject: [PATCH 1/2] Crude hack to force in context from a file. I believe doing this is necessary because the `b:workspace_folder` and `g:copilot_workspace_folders` appear to have no effect for me, at least with vim version 9.1. I have not investigated super deeply, but I'm guessing files from those directories are only used by the language server, rather than being added wholesale to the transmitted context. This is annoying for obvious reasons when it comes to files that the language server won't do anything with, in my case SQL. --- autoload/copilot/client.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/autoload/copilot/client.vim b/autoload/copilot/client.vim index c811062e..34c61d1d 100644 --- a/autoload/copilot/client.vim +++ b/autoload/copilot/client.vim @@ -77,6 +77,21 @@ function! s:Send(instance, request) abort if !has_key(a:instance, 'job') return v:false endif + if get(a:request,"method") == "textDocument/didChange" + let forced_files = [] + if exists("g:copilot_context_file") + let a:request['params']['contentChanges'][0]['text'] .= "\n" .. system("cat " .. shellescape(expand(g:copilot_context_file))) + let forced_files += [expand(g:copilot_context_file)] + endif + if exists("b:workspace_folder") && isdirectory(b:workspace_folder) + for file_to_force in glob(b:workspace_folder,v:false,v:true) + if index(forced_files,file_to_force) == -1 + let a:request['params']['contentChanges'][0]['text'] .= "\n" .. system("cat " .. shellescape(file_to_force)) + let forced_files += [file_to_force] + endif + endfor + endif + endif try call ch_sendexpr(a:instance.job, a:request) return v:true @@ -762,3 +777,5 @@ augroup copilot_close autocmd BufUnload * call s:CloseBuffer(+expand('')) endif augroup END + +# vim: sw=0 ts=2 et From 86e1bb44f7ff46be8b03e618e1aac70eeea38980 Mon Sep 17 00:00:00 2001 From: koyae Date: Thu, 20 Feb 2025 01:25:13 -0700 Subject: [PATCH 2/2] Fixed modeline so copilot code doesn't choke. For whatever reason the # vim: was foiling it. Tested and appears to work now. --- autoload/copilot/client.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/copilot/client.vim b/autoload/copilot/client.vim index 34c61d1d..fab9b6eb 100644 --- a/autoload/copilot/client.vim +++ b/autoload/copilot/client.vim @@ -778,4 +778,4 @@ augroup copilot_close endif augroup END -# vim: sw=0 ts=2 et +" vim: sw=0 ts=2 et