zbirenbaum / copilot-cmp

Lua plugin to turn github copilot into a cmp source
MIT License
1.07k stars 38 forks source link

attempt to index local 'opts' (a nil value) #70

Closed rgruyters closed 10 months ago

rgruyters commented 1 year ago

Since commit ad4c097bf76c544fce95a2cb6b02f245cb18a6bb I get a trace callback message when opening a file.

Error detected while processing LspAttach Autocommands for "*":
Error executing lua callback: ...azy/copilot-cmp/lua/copilot_cmp/completion_functions.lua:74: attempt to index local 'opts' (a nil value)
stack traceback:
        ...azy/copilot-cmp/lua/copilot_cmp/completion_functions.lua:74: in function 'init'
        ...l/share/nvim/lazy/copilot-cmp/lua/copilot_cmp/source.lua:45: in function 'new'
        ...cal/share/nvim/lazy/copilot-cmp/lua/copilot_cmp/init.lua:29: in function '_on_insert_enter'
        .../robin/.config/nvim/lua/grtrs/plugins/custom/copilot.lua:38: in function 'on_attach'
        /home/robin/.config/nvim/lua/grtrs/functions.lua:10: in function </home/robin/.config/nvim/lua/grtrs/functions.lua:7>
        [C]: in function 'nvim_exec_autocmds'
        /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1531: in function '_on_attach'
        /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1358: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I'm using Neovim version 0.9.0 and nvim-cmp (commit) version 3ac8d6c

xbladesub commented 1 year ago

same issue

dianchia commented 1 year ago

Same issue

zbirenbaum commented 1 year ago

The commit you referenced is a one line change adding a nil check to opts to fix this problem.

Can one of you post your config? I'm using no arguments to the setup function and can't reproduce this.

What I can do I guess is just make a new local var instead of reassigning the parameter in case it's a luajit thing, but I really don't know why this would be happening.

for reference, I'm on master, and this works fine:

{
    "zbirenbaum/copilot-cmp",
    config = function ()
      require("copilot_cmp").setup(nil)
    end,
},
cxzhou35 commented 1 year ago

The commit you referenced is a one line change adding a nil check to opts to fix this problem.

Can one of you post your config? I'm using no arguments to the setup function and can't reproduce this.

What I can do I guess is just make a new local var instead of reassigning the parameter in case it's a luajit thing, but I really don't know why this would be happening.

for reference, I'm on master, and this works fine:

{
    "zbirenbaum/copilot-cmp",
    config = function ()
      require("copilot_cmp").setup(nil)
    end,
},

I have the same issue, here is my config about copilot-cmp:

return {
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    build = ":Copilot auth",
    module = "copilot",
    opts = {
      suggestion = { enabled = false },
      panel = { enabled = false },
      filetypes = {
        yaml = false,
        markdown = false,
        help = false,
        gitcommit = false,
        gitrebase = false,
        hgcommit = false,
        svn = false,
        cvs = false,
      },
    },
  },
  {
    "zbirenbaum/copilot-cmp",
    dependencies = "copilot.lua",
    event = { "InsertEnter", "LspAttach" },
    fix_pairs = true,
    config = function(_, opts)
      local copilot_cmp = require("copilot_cmp")
      copilot_cmp.setup(opts)
      -- attach cmp source whenever copilot attaches
      -- fixes lazy-loading issues with the copilot cmp source
      require("lazyvim.util").on_attach(function(client)
        if client.name == "copilot" then
          copilot_cmp._on_insert_enter({})
        end
      end)
    end,
  },
}

Btw, this config is based on LazyVim.

zbirenbaum commented 1 year ago

I'm wondering if the 'opts' the stack trace is referring to is actually the one in your config function. Could you try setting your config to be identical to mine? Just call the setup function with no args

rgruyters commented 11 months ago

Sorry for the delay, missed your question apparently. Anyway here is my copilot config

rgruyters commented 11 months ago

I noticed the issue gets triggered when you open a file and Copilot gets enabled in the background, but if do something quickly in between time, it triggers the error. (e.g. open Git status via tpope fugitive plugin or open Telescope window)

zbirenbaum commented 10 months ago

I can't reproduce this and most users don't have the issue. If it is still a problem please change your plugin startup order to initialize copilot-cmp earlier or later and that should fix the issue.