CopilotC-Nvim / CopilotChat.nvim

Chat with GitHub Copilot in Neovim
https://copilotc-nvim.github.io/CopilotChat.nvim/
GNU General Public License v3.0
1.5k stars 69 forks source link

Buffer with this name already exists #302

Closed elynnaie closed 4 months ago

elynnaie commented 4 months ago

The issue is: if I open the Copilot chat window and then edit and save my ~/.vimrc (for which I have an autosource as you can see below), attempting to open Copilot chat again produces the following error:

Error executing Lua callback: ...e/.vim/plugged/CopilotChat.nvim/lua/CopilotChat/chat.lua:43: Vim:E95: Buffer with this name already exists                               
stack traceback:
        [C]: in function 'nvim_buf_set_name'
        ...e/.vim/plugged/CopilotChat.nvim/lua/CopilotChat/chat.lua:43: in function 'buf_create'
        ...vim/plugged/CopilotChat.nvim/lua/CopilotChat/overlay.lua:38: in function 'validate'
        ...e/.vim/plugged/CopilotChat.nvim/lua/CopilotChat/chat.lua:109: in function 'open'
        ...e/.vim/plugged/CopilotChat.nvim/lua/CopilotChat/init.lua:301: in function <...e/.vim/plugged/CopilotChat.nvim/lua/CopilotChat/init.lua:281>

My vim config:

Plug 'zbirenbaum/copilot.lua'    
Plug 'nvim-lua/plenary.nvim'    
Plug 'CopilotC-Nvim/CopilotChat.nvim', { 'branch': 'canary' }    
noremap <silent> <leader>co :<C-U>CopilotChatOpen<CR>    
noremap <silent> <leader>cc :<C-U>CopilotChatClose<CR>    
noremap <silent> <leader>ct :<C-U>CopilotChatToggle<CR>                                                                                                                          
noremap <silent> <leader>ce :<C-U>CopilotChatExplain<CR>                                                                                                                         
noremap <silent> <leader>cf :<C-U>CopilotChatFix<CR>

augroup autosourcing
    autocmd!                    
    autocmd BufWritePost .vimrc source %                         
augroup END

...

lua << EOF                                                                                                                                                                       
require("CopilotChat").setup {                                                                                                                                                   
  debug = true, -- Enable debugging                                                                                                                                              
  -- See Configuration section for rest                                                                                                                                          
  window = {                                                                                                                                                                     
      layout = 'float',                                                                                                                                                          
      relative = 'cursor',                                                                                                                                                       
      width = 1,                                                                                                                                                                 
      height = 0.4,                                                                                                                                                              
      row = 1                                                                                                                                                                    
    }                                                                                                                                                                            
}                                                                                                                                                                                
EOF

There is an easy workaround (close vim entirely and reopen), but it would be nice if this could be addressed.