jellydn / CopilotChat.nvim

Chat with GitHub Copilot in Neovim
GNU General Public License v3.0
100 stars 9 forks source link

pynvim.api.common.NvimError: Vim:E121: Undefined variable: g:copilot_chat_view_option #30

Closed ecosse3 closed 8 months ago

ecosse3 commented 8 months ago

Describe the bug

When I try to use CopilatChat anything command I get error:

image

error caught in async handler '/Users/lukasz.kurpiewski/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py:command:CopilotChat [['w
hat does it do']]'
Traceback (most recent call last):
  File "/Users/lukasz.kurpiewski/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py", line 55, in copilotChat
    view_option = self.nvim.eval("g:copilot_chat_view_option")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynvim/api/nvim.py", line 319, in eval
    return self.request('nvim_eval', string, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynvim/api/nvim.py", line 199, in request
    res = self._session.request(name, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynvim/msgpack_rpc/session.py", line 139, in request
    raise self.error_wrapper(err)
pynvim.api.common.NvimError: Vim:E121: Undefined variable: g:copilot_chat_view_option
  {
    "jellydn/CopilotChat.nvim",
    event = "VeryLazy",
    opts = {
      mode = "split",
      prompts = {
        Explain = "Explain how it works.",
        Review = "Review the following code and provide concise suggestions.",
        Tests = "Briefly explain how the selected code works, then generate unit tests.",
        Refactor = "Refactor the code to improve clarity and readability.",
      },
    },
    build = function()
      vim.defer_fn(function()
        vim.cmd("UpdateRemotePlugins")
        vim.notify("CopilotChat - Updated remote plugins. Please restart Neovim.")
      end, 3000)
    end,
    config = function()
      local present, wk = pcall(require, "which-key")
      if not present then
        return
      end

      wk.register({
        c = {
          c = {
            name = "Copilot Chat",
          }
        }
      }, {
        mode = "n",
        prefix = "<leader>",
        silent = true,
        noremap = true,
        nowait = false,
      })
    end,
    keys = {
      { "<leader>ccc", ":CopilotChat ",                desc = "CopilotChat - Prompt" },
      { "<leader>cce", ":CopilotChatExplain ",         desc = "CopilotChat - Explain code" },
      { "<leader>cct", "<cmd>CopilotChatTests<cr>",    desc = "CopilotChat - Generate tests" },
      { "<leader>ccr", "<cmd>CopilotChatReview<cr>",   desc = "CopilotChat - Review code" },
      { "<leader>ccR", "<cmd>CopilotChatRefactor<cr>", desc = "CopilotChat - Refactor code" },
    }
  },

I see it's an issue with pynvim. I already removed it from pip, checked different Python versions, removed pip cache, installed with --no-cache-dir option. Nothing helps. It was working fine and after some update just happend like this.

I also tried using lazy = false flag for plugin but doesn't change anything.

When I run :UpdateRemotePlugins:

remote/host: python3 host registered plugins ['copilot-plugin.py']
remote/host: generated rplugin manifest: /Users/lukasz.kurpiewski/.local/share/nvim/rplugin.vim

I have no idea what's the issue.

Reproduction

Just use command

System Info

System:
    OS: macOS 14.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 887.22 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/Library/Caches/fnm_multishells/89082_1706370365515/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.1.0 - ~/Library/Caches/fnm_multishells/89082_1706370365515/bin/npm
    pnpm: 8.8.0 - ~/Library/pnpm/pnpm
    bun: 1.0.20 - ~/.bun/bin/bun
    Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 121.0.6167.85
    Safari: 17.3

Additionally:

Python 3.11.7
pip 23.3.2 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)
NVIM v0.10.0-dev-2191+g4e59422e1
Build type: RelWithDebInfo
LuaJIT 2.1.1706032906

Info from `checkhealth`:

Python 3 provider (optional) ~
- pyenv: Path: /opt/homebrew/Cellar/pyenv/2.3.35/libexec/pyenv
- pyenv: $PYENV_ROOT is not set. Infer from `pyenv root`.
- WARNING pyenv: Root does not exist: /Users/lukasz.kurpiewski/.pyenv. Ignoring pyenv for all following checks.
- Using: g:python3_host_prog = "/opt/homebrew/bin/python3"
- Executable: /opt/homebrew/bin/python3
- Python version: 3.11.7
- pynvim version: 0.5.0
- OK Latest pynvim is installed.

Python virtualenv ~
- OK no $VIRTUAL_ENV

Used Package Manager

npm

Validations

ecosse3 commented 8 months ago

I couldn't figure it out for couple days... and now I just removed:

 config = function()
      local present, wk = pcall(require, "which-key")
      if not present then
        return
      end

      wk.register({
        c = {
          c = {
            name = "Copilot Chat",
          }
        }
      }, {
        mode = "n",
        prefix = "<leader>",
        silent = true,
        noremap = true,
        nowait = false,
      })
    end,

and it started working! I don't know why the config option doesn't work for this plugins. I've added WhichKey name in different file and it works.

Leaving this commend if anyone else will get same issue. Have no idea why it happens.