diff --git a/README.md b/README.md index 0f9ed9e4..2096509c 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,12 @@ require("copilot").setup { } ``` +### git commit messages + +When editing a commit message (`gitcommit` filetype), Copilot uses the staged +diff (`git diff --staged`) to generate commit message suggestions. Enable +`gitcommit` in the `filetypes` table to use this feature. + ### logger Logs will be written to the `file` for anything of `file_log_level` or higher. diff --git a/doc/copilot.txt b/doc/copilot.txt index 2d62d298..4a0d3979 100644 --- a/doc/copilot.txt +++ b/doc/copilot.txt @@ -299,6 +299,11 @@ won’t be used anymore. e.g. } < +GIT COMMIT MESSAGES~ + +When editing a commit message (`gitcommit` filetype), Copilot fetches the +staged diff (`git diff --staged`) to provide commit message suggestions. Enable +`gitcommit` in the |copilot-filetypes| table to use this feature. LOGGER ~ diff --git a/lua/copilot/util.lua b/lua/copilot/util.lua index 41b94e33..ab7b211c 100644 --- a/lua/copilot/util.lua +++ b/lua/copilot/util.lua @@ -74,6 +74,13 @@ function M.get_doc() position = params.position, } + if vim.bo.filetype == "gitcommit" then + local ok, diff = pcall(vim.fn.system, { "git", "diff", "--staged", "--no-color" }) + if ok and diff and diff ~= "" then + doc.gitDiff = diff + end + end + return doc end