Skip to content

Copilot.lua: TypeError when running Copilot version command #466

Description

@yongshengzhucn

Description

When running the command Copilot version in Neovim, an error occurs due to attempting to concatenate a table value with a string using the .. operator.

Error Message

Error executing Lua callback: ...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:23: ...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:22: attempt to concatenate upvalue 'lines' (a table value)
stack traceback:
	[builtin#36]: at 0x0100e48fc4
	...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:23: in function <...ocal/share/nvim/lazy/copilot.lua/lua/copilot/command.lua:8>
	...ng/.local/share/nvim/lazy/copilot.lua/plugin/copilot.lua:41: in function <...ng/.local/share/nvim/lazy/copilot.lua/plugin/copilot.lua:9>

Problematic Code

In command.lua, function M.version():

function M.version()
  local info = u.get_editor_info()
  ---@type string
  local lines = {
    info.editorInfo.name .. " " .. info.editorInfo.version,
    "copilot language server" .. " " .. info.editorPluginInfo.version,
    "copilot.lua" .. " " .. u.get_copilot_lua_version(),
  }
  local client = c.get()
  coroutine.wrap(function()
    local server_info = lsp.get_server_info(client)
    logger.notify(lines .. "\n" .. server_info)  -- This line causes the error
  end)()
end

Root Cause

The variable lines is a table, but the code attempts to concatenate it with a string using the .. operator, which is not valid in Lua. Tables cannot be directly concatenated with strings.

Suggested Fix

Replace the problematic line with:

logger.notify(table.concat(lines, "\n") .. "\n" .. server_info)

This uses table.concat() to properly convert the table to a string before concatenation.

Environment

  • Neovim version: v0.11.0
  • Operating System: macOS

Additional Information

The error occurs only when trying to display version information with the Copilot version command.

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