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

[Copilot] not initialized - potential nodejs issue #254

Closed NicoGGG closed 6 months ago

NicoGGG commented 6 months ago

Hello,

I am having issue with copilot suddenly. When I run :Copilot I always get this error

Error executing Lua callback: ...local/share/nvim/lazy/copilot.lua/lua/copilot/config.lua:72: [Copilot] not initialized                                                      
stack traceback:
        [C]: in function 'error'
        ...local/share/nvim/lazy/copilot.lua/lua/copilot/config.lua:72: in function 'get'
        ...local/share/nvim/lazy/copilot.lua/lua/copilot/client.lua:52: in function 'get_node_version'
        ...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:75: in function 'flush_lines'
        ...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:94: in function <...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:56>
        ...co/.local/share/nvim/lazy/copilot.lua/plugin/copilot.lua:39: in function <...co/.local/share/nvim/lazy/copilot.lua/plugin/copilot.lua:8>

I saw an old issue talking about going back to node16 but it does exactly the same. Which is weird considering that if I read the code correctly, now you are not supposed to have node < 18 to make it work.

According to the stacktrace, this line is crashing: local node = config.get("copilot_node_command") in copilot/client.lua:52

My node --version output is v18.18.2. I use nvm for node version management.

Does anyone else have the same issue ? If it is just me do you have a clue what could cause that ? The weird thing is that is used to work, and suddenly it does this. I don't remember changing anything on the nodejs part of my setup.

Thanks a lot in advance

MunifTanjim commented 6 months ago

Are you following the instructions?

https://github.com/zbirenbaum/copilot.lua?tab=readme-ov-file#setup-and-configuration

Did you call the .setup function?

NicoGGG commented 6 months ago

I did initially c-cd this and it was working.

I am still new to neovim and lua and read somewhere that the setup() method is implicitly called so I removed it later on. But actually the config field must be set to at least true to do that. So setting config = true is doing the trick. Also, I just discovered that passing options to opts will also implicitly call setup()

So in the end this

return {
  "zbirenbaum/copilot.lua",
  cmd = "Copilot",
  event = "InsertEnter",
  opts = {
    suggestion = {
      auto_trigger = true,
    },
  },
}

and this

return {
  "zbirenbaum/copilot.lua",
  cmd = "Copilot",
  event = "InsertEnter",
  config = true,
}

both do the trick

I know you probably know that but just in case an another neovim beginner is having trouble with that.

Thank you very much for the quick answer and for putting me back on track !