-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite to diff: feature request #191
Comments
this works for me as a workaround for now: vim.keymap.set({ "x" }, "<space>cd", ":GpDiff ", { remap = true, desc = "[C]opilot rewrite to [D]iff" })
function _G.gp_diff(args, line1, line2)
local contents = vim.api.nvim_buf_get_lines(vim.api.nvim_get_current_buf(), 0, -1, false)
vim.cmd("vnew")
local scratch_buf = vim.api.nvim_get_current_buf()
vim.bo[scratch_buf].buftype = "nofile"
vim.bo[scratch_buf].bufhidden = "wipe"
vim.api.nvim_buf_set_lines(scratch_buf, 0, -1, false, contents)
vim.cmd(line1 .. "," .. line2 .. "GpRewrite " .. args)
vim.defer_fn(function()
vim.cmd("diffthis")
vim.cmd("wincmd p")
vim.cmd("diffthis")
end, 1000)
end
vim.cmd("command! -range -nargs=+ GpDiff lua gp_diff(<q-args>, <line1>, <line2>)") |
i had a similar requirement. i ended up adding a new custom hook: hooks = {
RewriteToDiff = function(gp, params)
local template = 'I have the following from {{filename}}:\n\n'
.. '```{{filetype}}\n{{selection}}\n```\n\n'
.. 'Rewrite it based on these instructions: {{command}}\n\n'
.. 'Respond with the following:\n\n'
.. ' - a code block containing the rewritten code\n\n'
.. ' - a brief explanation of the changes that were made along with the reasons for doing so\n\n'
.. ' - a "diff" code block that shows the code changes in a diff format.\n\n'
local agent = gp.get_chat_agent()
local input_prompt = '🤖 ' .. agent.name .. ' ~'
gp.Prompt(params, gp.Target.popup, agent, template, input_prompt)
end
} i can then execute it with a visual selection, which also triggers the input: vim.keymap.set('v', '<C-a>e', ":<C-u>'<,'>GpRewriteToDiff<cr>", keymapOptions '[e]dit') and it appears in a popup: i feel like there is a lot of power hidden behind the custom hooks @Robitx. It would be super cool to expand this out a lot more. Your library has the cleanest abstraction of all the ai plugins and ide's i have tested. it would be great to show different workflows in more detail, exposing how you can combine the idea of visual selection with inputs and the various modes. i'm also keen on a mode that is a merge of the command hooks and the new chat buffer mode behaviours - i.e. do a visual selection, with some sort of input and intended behaviour, with the result then going into a new chat rather than a a throw away split/popup/etc. then i'd be able to continue conversing in regards to the response, and have it in my history for later retrieval. hat tip though. this is all stellar work. |
The way that claude.vim implements rewrite functionality is pretty nice: The edited file contents are written to a new split and a diff is automatically opened. It is basically a mix of
:GpRewrite
and:GpVnew
.It's possible to mirror this functionality with git and, e.g., fugitives
:Gvdiff
, but in that case I have to stage my changes beforehand. I could probably even automate this, by opening a split and copying the file contents there, before running:GpRewrite
, and then diffing.I'd still like to propose adding this directly to gp.nvim.
The text was updated successfully, but these errors were encountered: