yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
6.51k stars 237 forks source link

bug: Cannot accept diff #757

Open xajik opened 6 days ago

xajik commented 6 days ago

Describe the bug

I'm new to nvim, so please excuse my ignorance. After I try to apply the diff, I cannot accept it with the default key binding as it enters CHANGE mode instead.

":nmap ca"

Screenshot 2024-10-24 at 2 58 17 PM

press "c":

Screenshot 2024-10-24 at 2 59 11 PM ct: -> accept their code BUT: ca: -> LSP Code Action ### To reproduce 1. Apply diff 2. Press "c" ### Expected behavior how do I use default key binding that it doesn't collide with +Change mode? ### Installation method Use lazy.nvim: ```lua return { { "yetone/avante.nvim", event = "VeryLazy", lazy = false, version = false, -- set this if you want to always pull the latest change opts = { provider = "copilot", auto_suggestions_provider = "copilot", mappings = { diff = { ours = "co", -- Use our changes theirs = "ct", -- Use their changes all_theirs = "ca", -- Use all their changes both = "cab", -- Use both changes cursor = "cc", -- Use changes at cursor next = "]x", -- Go to next change prev = "[x", -- Go to previous change }, }, }, -- if you want to build from source then do `make BUILD_FROM_SOURCE=true` build = "make", -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows dependencies = { "nvim-treesitter/nvim-treesitter", "stevearc/dressing.nvim", "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", --- The below dependencies are optional, "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons "zbirenbaum/copilot.lua", -- for providers='copilot' { -- support for image pasting "HakonHarnes/img-clip.nvim", event = "VeryLazy", opts = { -- recommended settings default = { embed_image_as_base64 = false, prompt_for_file_name = false, drag_and_drop = { insert_mode = true, }, -- required for Windows users use_absolute_path = true, }, }, }, { -- Make sure to set this up properly if you have lazy=true 'MeanderingProgrammer/render-markdown.nvim', opts = { file_types = { "markdown", "Avante" }, }, ft = { "markdown", "Avante" }, }, }, }, } ``` ### Environment neovim ### Repro _No response_
xajik commented 5 days ago

I installed https://github.com/akinsho/git-conflict.nvim and still face the same issues with c - whatever starts with it, it turn on Change mode. What did I miss?

xajik commented 4 days ago

Is it possible to force replace key binding when diff is active?

teocns commented 4 days ago

Diff accept is very sensitive I must admit. I face weird behaviors too, but I guess it also has to do with the global autocmd integrity state of our own personal configs

xajik commented 4 days ago

Diff accept is very sensitive I must admit. I face weird behaviors too, but I guess it also has to do with the global autocmd integrity state of our own personal configs

I see there is already function to toggle key mapping when conflict is detected. But it doesn't work properly for me. Any suggestions?

https://github.com/yetone/avante.nvim/blob/f9520c4fdfed08e9cc609d6cd319b358e4ea33a5/lua/avante/diff.lua#L384

aarnphm commented 3 days ago

Sorry for the ping @b0o, but can you try whether you can replicate this? I can't seem to reproduce at all

xajik commented 3 days ago

Sorry for the ping @b0o, but can you try whether you can replicate this? I can't seem to reproduce at all

Thanks, @aarnphm! Did you disable default c - change, behavior on your side? I asked the same on Reddit and got similar suggestion, but I don't want to remove it. https://www.reddit.com/r/neovim/comments/1gbneis/comment/ltngnj2/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

xajik commented 3 days ago

BTW, when I try to do :nmap c without conflict, I see "no mapping".

But when I press c it will enter change mode.

Screenshot 2024-10-27 at 12 41 06 PM
aarnphm commented 3 days ago

No I use default mapping

Also the conflict mappings are registered only if "AvanteConflictDetected" autocmd is available

https://github.com/yetone/avante.nvim/blob/5c02a5d846a17b9f9db40cf64caa0bc75e7b13c1/lua/avante/diff.lua#L389

This means my default there is no c- mapping, which is intentional so that it won't conflict with users mapping

b0o commented 2 days ago

I can reproduce this if I wait for longer than timeoutlen between pressing c and o/t/c/a. If I set timeoutlen really low, like 50-100ms, it's very hard to trigger the avante mapping. If I set it higher, it's easier.

b0o commented 2 days ago

After pressing c and waiting timeoutlen ms, vim enters operator-pending mode. While in this mode, normal mode mappings don't apply, as vim is waiting for a movement to complete the c ("change") operator. This is why trying to press o/t/c/a won't have the desired effect.

For now, I think the best workarounds are for the user to either increase their timeoutlen, or to configure a prefix other than c.

On Avante's side, one possible solution could be to override timeoutlen with a higher value while the cursor is over a diff. This could be optional behind a configuration flag.

aarnphm commented 2 days ago

Thanks for investigating this. I'm good with increasing timeoutlen from avante during diff mode (gated behind an option, we can provide a "reasonable" default)

edit: I use timeoutlen=300 and works for me