Skip to content

Copilot stops attaching to buffers at some point #359

Description

@j-xella

There were no such problems earlier, but recently I updated to:

  • NVIM v0.11.0-dev-1701+g38a52caec0 (built from sources locally)
  • copilot.lua - commit 886ee73
  • copilot_cmp - commit 15fc12a

The config didn't change. I use lazy as my package manager. The plugin does not display the copilot hints itself, but rather provides them to the completion plugin nvim-cmp via copilot_cmp plugin

return {
  {
    "zbirenbaum/copilot.lua",
    cmd = { "Copilot", },
    -- event = { 'InsertEnter' }, -- no need, it will be enabled with nvim-cmp
    config = function (_,_)

      vim.g.copilot_proxy = [[******]]
      vim.g.copilot_proxy_strict_ssl = false
      -- TODO: Maybe, in the funture, not even store them here, but get from ~/.curlrc ???

      require("copilot").setup({
        suggestion = { enabled = false, },
        panel = { enabled = false, },
        copilot_node_command = '/full/path/to/node', -- in case it is not in path yet
      })
    end,
  },
  {
    "zbirenbaum/copilot-cmp",
    lazy = true,
    dependencies = {
      "zbirenbaum/copilot.lua",
    },
    config = function (_,_)
      require("copilot_cmp").setup()
    end,
  },
}

When neovim is just opened, first couple of files are usually OK. I see copilot hints in autocompletion list, and I see something similar to:

:Copilot status

Copilot] Online
[Copilot] Enabled for lua --- (or any other language)

:checkhealth

LSP configs active in this buffer (bufnr: 41) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `lua`
- 2 client(s) attached to this buffer
...
- Client: `copilot` (id: 2, bufnr: [28, 41, 123, 9])
  root directory:    /xxxxxxx/yyy/zzz
  filetypes:         
  cmd:               ~/linux/local/bin/node /users/XXXXXX/.local/share/nvim/lazy/copilot.lua/copilot/index.js
  version:           `v22.11.0`
  executable:        true
  autostart:         false

However, as I keep opening more buffers, and sometimes when the existing buffer is reloaded due to external changes, there are no more copilot suggestions. I start getting:

:Copilot status

[Copilot] Online
[Copilot] Disabled manually for cpp --- (or any other language, could be even one that works in other buffers)

:checkhealth

-- Similar to the previous one, but the current buffer is not in the list

If I now try enabling copilot manually for such buffer, I get this:

:Copilot enable

Error executing vim.schedule lua callback: ...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:21: unexpectedly started multiple copilot server
stack traceback:
        [C]: in function 'error'
        ...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:21: in function 'store_client_id'
        ...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:102: in function 'buf_attach'
        ...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:260: in function <...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:259>

:checkhealth

LSP configs active in this buffer (bufnr: 114) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `cpp`
- 2 client(s) attached to this buffer
...
- Client: `copilot` (id: 5, bufnr: [114])
  root directory:    /xxx/yy/zz
  filetypes:         
  cmd:               ~/linux/local/bin/node /users/XXXX/.local/share/nvim/lazy/copilot.lua/copilot/index.js
  version:           `v22.11.0`
  executable:        true
  autostart:         false
- 3 active client(s) not attached to this buffer:
...
- Client: `copilot` (id: 2, bufnr: [28, 41, 123, 9])
  root directory:    /xxx/yy/zz
  filetypes:         
  cmd:               ~/linux/local/bin/node /users/XXXXX/.local/share/nvim/lazy/copilot.lua/copilot/index.js
  version:           `v22.11.0`
  executable:        true
  autostart:         false

First, we have 2 copilot clients now. Second, the new client (id=5), even though seems attached to the current buffer, does not do anything.

Some new buffers may be lucky and get attached of the original copilot client (id=2). The copilot suggestions work for all the buffers attached to the original client, both old and new. Otherwise, not :(

The above error may also appear by itself (on events, I presume), for example when reloading files.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions