Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copilot stops attaching to buffers at some point #359

Closed
j-xella opened this issue Feb 6, 2025 · 3 comments
Closed

Copilot stops attaching to buffers at some point #359

j-xella opened this issue Feb 6, 2025 · 3 comments
Assignees

Comments

@j-xella
Copy link

j-xella commented Feb 6, 2025

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.

@AntoineGS
Copy link
Collaborator

From what I can see this should be fixed with #377 as I ended up making some changes to prevent multiple instances of Copilot from running, as it was happening very often with workspaces active.

AntoineGS added a commit to AntoineGS/copilot.lua that referenced this issue Mar 15, 2025
Prevents scenarios where a second client could be created and cause and caught in store_client_id.
May fix zbirenbaum#359
AntoineGS added a commit to AntoineGS/copilot.lua that referenced this issue Mar 15, 2025
Prevents scenarios where a second client could be created and cause and caught in store_client_id.
May fix zbirenbaum#359
AntoineGS added a commit to AntoineGS/copilot.lua that referenced this issue Mar 15, 2025
Prevents scenarios where a second client could be created and cause and caught in store_client_id.
May fix zbirenbaum#359
@AntoineGS
Copy link
Collaborator

The PR has been merged, can you report back if the issue is fixed or persists?
If it persists, could you activate the logging as such and post the log file?

    require("copilot").setup {
      ...
      logger = {
        file_log_level = vim.log.levels.TRACE,
        log_to_file = true,
        trace_lsp = "verbose",
      },
      ...

Thanks!

@AntoineGS AntoineGS self-assigned this Mar 21, 2025
@AntoineGS
Copy link
Collaborator

Closing as completed for now, if you report back that it is not fixed I will reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants