zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.43k stars 64 forks source link

copilot.lua appends typed characters between auto-triggered suggestion and accept when debounce > 0 #259

Closed jtackaberry closed 5 months ago

jtackaberry commented 6 months ago

You're typing a line of code and copilot shows ghost text of a potential suggestion. If you immediately accept the suggestion (using <M-l> as is the default configuration) then all is good. However, if you type a few characters into the suggestion after the ghost text appears, once you accept the suggestion, whatever characters you typed in the previous debounce amount of time become appended to the end of the accepted suggestion.

I use AstroNvim and am constantly running into this. I did up a from-scratch nvim config with just lazy.nvim and zbirenbaum/copilot.lua and wasn't able to reproduce it nearly as much, but it still sometimes occurred. Finally I realized why: in addition to auto_trigger=true (which I want) astronvim's community plugin sets debounce=150 whereas copilot.lua's default is 75, so the issue is much more frequently hit with Astronvim.

It still occurs with 75, as I said, but of course the window is much smaller. Unsurprisingly, it vanishes with debounce=0.

The screen capture below shows two cases. The first scenario demonstrates the working case, where the suggestion is accepted immediately without typing anything further: I type func mai, wait for the suggestion, and then <M-l> to accept. The second scenario shows typing the first 3 letters of the suggestion after the ghost text appears: I type func m, wait for the suggestion, quickly type ain and then <M-l> to accept. In this latter case, the ain I typed between suggestion and accept is appended to the end.

nvim-copilot

Lazy configuration is as follows. No other plugins are loaded apart from folke/lazy.nvim:

plugins = {
    {
        "zbirenbaum/copilot.lua",
        cmd = "Copilot",
        event = "InsertEnter",
        config = function()
            require("copilot").setup({
                suggestion = {
                    auto_trigger = true,
                    debounce = 150,
                },
            })
        end,
    },
}
require("lazy").setup(plugins, {})
Rubenduburck commented 5 months ago

Same issue here

9mm commented 5 months ago

Already addressed here, no word yet from @MunifTanjim yet

https://github.com/zbirenbaum/copilot.lua/issues/251

MunifTanjim commented 5 months ago

Can you check if https://github.com/zbirenbaum/copilot.lua/commit/3c6a1d24d8afc70a75bae2c1c3a9a09223ebbb9f fixes it?

jtackaberry commented 5 months ago

Can you check if https://github.com/zbirenbaum/copilot.lua/commit/3c6a1d24d8afc70a75bae2c1c3a9a09223ebbb9f fixes it?

@MunifTanjim so far so good! Simple test case from my OP now works even with debounce=500, and I haven't encountered any similar issues with a bit more real coding.

Thanks!

MunifTanjim commented 5 months ago

Let's reopen if the issue comes back again.

Rubenduburck commented 5 months ago

Seems to work here too