Skip to content
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

Open
fneu opened this issue Aug 6, 2024 · 1 comment
Open

Rewrite to diff: feature request #191

fneu opened this issue Aug 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@fneu
Copy link

fneu commented Aug 6, 2024

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.

@Robitx Robitx added the enhancement New feature or request label Aug 6, 2024
@fneu
Copy link
Author

fneu commented Aug 6, 2024

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>)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants