Skip to content

odecompanion extension: make_vars crashes — config.interactions.chat.variables is nil #278

Description

@wom

The codecompanion extension's variables.lua crashes on startup when make_vars = true. The error occurs because config.interactions.chat.variables does not exist in the current version of codecompanion.nvim.

Error:

   Error executing vim.schedule lua callback: ...b.nvim/lua/mcphub/extensions/codecompanion/variables.lua:20: bad argument #1 to 'pairs' (table expected, got nil)
   stack traceback:
           [C]: in function 'pairs'
           ...b.nvim/lua/mcphub/extensions/codecompanion/variables.lua:20: in function 'register'
           ...b.nvim/lua/mcphub/extensions/codecompanion/variables.lua:92: in function ''
           vim/_editor.lua: in function <vim/_editor.lua:0>

Root cause:

In variables.lua:18, the extension does:

   local cc_variables = config.interactions.chat.variables

But config.interactions.chat.variables is nil in the current codecompanion.nvim. The field appears to have been removed or renamed in a recent codecompanion update. The subsequent pairs(cc_variables) on line 20 then errors.

Workaround:

  Set make_vars = false in the extension config:

   extensions = {
       mcphub = {
           callback = "mcphub.extensions.codecompanion",
           opts = {
               make_vars = false,
               make_slash_commands = true,
               show_result_in_chat = true,
           },
       },
   },

Suggested fix:

Add a nil check before iterating in variables.lua:

   local cc_variables = config.interactions.chat.variables
   if not cc_variables then
       return
   end

Or update to use whatever the current codecompanion API is for registering chat variables.

Environment:

  • Neovim: v0.11.2
  • mcphub.nvim: 7cd5db3 (main)
  • codecompanion.nvim: a3bf350 (main)
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions