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

Errors using .accept API #278

Open ldelossa opened 4 months ago

ldelossa commented 4 months ago

Hello.

I'm trying to use Copilot in a 'super-tab' fashion like this:

local keys = {
  ['tab']        = vim.api.nvim_replace_termcodes('<Tab>', true, true, true),
  ['ctrl-y']     = vim.api.nvim_replace_termcodes('<C-y>', true, true, true),
  ['ctrl-tab']   = vim.api.nvim_replace_termcodes('<C-Tab>', true, true, true),
}
_G.tab_action = function()
  if vim.fn.pumvisible() ~= 0 then
    return keys['ctrl-y']
    elseif require("copilot.suggestion").is_visible() then
    require("copilot.suggestion").accept()
        return
  else
    return keys['tab']
  end
end
vim.keymap.set('i', '<Tab>', 'v:lua._G.tab_action()', { expr = true })

However, whenever I try to use tab to fill in a suggestion I get the following Neovim here:

E5108: Error executing lua /usr/share/nvim/runtime/lua/vim/lsp/util.lua:515: E565: Not allowed to change text or change window                                                                                    
stack traceback:                                                                                                                                                                                                  
        [C]: in function 'nvim_buf_set_text'                                                                                                                                                                      
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:515: in function 'apply_text_edits'                                                                                                                          
        ...ite/pack/deps/opt/copilot.lua/lua/copilot/suggestion.lua:487: in function 'accept'                                                                                                                     
        /home/louis/git/dotfiles/config/nvim/init.lua:503: in function </home/louis/git/dotfiles/config/nvim/init.lua:499>  
dinhmai74 commented 4 months ago

same here

vinicius507 commented 3 months ago

Same here. I'm using neovim 0.9.4,. It only happens when using require("copilot.suggestion").accept, if I use require("copilot.suggestion").accept_word it works.

Here's a stack trace:

E5108: Error executing lua: ...-unwrapped-0.9.4/share/nvim/runtime/lua/vim/lsp/util.lua:501: Failed to save undo information
stack traceback:
    [C]: in function 'nvim_buf_set_text'
    ...-unwrapped-0.9.4/share/nvim/runtime/lua/vim/lsp/util.lua:501: in function 'apply_text_edits'
    ...l/share/nvim/lazy/copilot.lua/lua/copilot/suggestion.lua:487: in function 'accept'
    /home/vini/.config/nvim/lua/plugins/coding.lua:10: in function </home/vini/.config/nvim/lua/plugins/coding.lua:8>