Enable Copilot to generate Git commit messages based on staged changes
I've configured copilot.vim to work on Git commit message as follows:
let g:copilot_filetypes = {
\ 'gitcommit': v:true,
\}
However, the suggestions don't seem to take into account the staged changes.
Related to https://github.com/github/copilot.vim/issues/66.
If you do git commit --verbose then the full diff of the commit should be able in the buffer for Copilot to use as context
That works better, thanks. But, I guess we still don't have the full repository context, which presumably would make the predictions better?
the full repository context, which presumably would make the predictions better?
Does the g:copilot_workspace_folders look relevant? 🤔
the full repository context, which presumably would make the predictions better?
Does the
g:copilot_workspace_folderslook relevant? 🤔
Yes, I saw that, bur the value would change dynamically.
the full repository context, which presumably would make the predictions better?
Does the
g:copilot_workspace_folderslook relevant? 🤔Yes, I saw that, bur the value would change dynamically.
Sort of this should depict what I mean:
let g:copilot_workspace_folders = g:copilot_workspace_folders + [expand('%:p:h')]
(the expand('%:p:h') expands to directory of the file which is being opened by vim)
You can check the resulting value then using :echo keys(copilot#Client().workspaceFolders) (ref)
Maybe also expand file's dir to repo root for a more proper context and return file's dir otherwise:
function! GetFileRepoRoot()
let l:file_path = expand('%:p')
let l:file_dir = expand('%:p:h')
if empty(l:file_path) || !filereadable(l:file_path)
return
endif
let l:git_root = system('git -C ' . shellescape(l:file_dir) . ' rev-parse --show-toplevel')
if v:shell_error == 0
return substitute(l:git_root, '\n\+$', '', '')
endif
return l:file_dir
endfunction
let g:copilot_workspace_folders = ["~/projects/", "/some/other/global/path/", GetFileRepoRoot()]
Your mileage may vary though.
function! GetFileRepoRoot() let l:file_path = expand('%:p') let l:file_dir = expand('%:p:h')
if empty(l:file_path) || !filereadable(l:file_path)
return
endif
let l:git_root = system('git -C ' . shellescape(l:file_dir) . ' rev-parse --show-toplevel')
if v:shell_error == 0
return substitute(l:git_root, '\n\+$', '', '')
endif
return l:file_dir
endfunction let g:copilot_workspace_folders = ["~/projects/", "/some/other/global/path/", GetFileRepoRoot()]
let g:copilot_filetypes = { \ 'gitcommit': v:true, }