codecompanion.nvim icon indicating copy to clipboard operation
codecompanion.nvim copied to clipboard

[Bug]: Attempt to index a nil value when opening new chat

Open tarjeir opened this issue 2 years ago • 1 comments

Your minimal.lua config


local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
      {
        "stevearc/dressing.nvim",
        opts = {},
      },
    },
    config = function()
      require("codecompanion").setup({
        adapters = {
          ollama = require("codecompanion.adapters").use("ollama", {
            schema = {
              model = {
                default = "llama3",
              },
              num_predict = {
                default = 500
              }
            },
          }),
        },
        strategies = {
          chat = {
            adapter = "ollama",
          },
          inline = {
            adapter = "ollama",
          },
          agent = {
            adapter = "anthropic",
          },
        },
      })
    end,
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- setup treesitter
local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if ok then
  treesitter.setup({
    ensure_installed = "all",
    ignore_install = { "phpdoc" }, -- list of parser which cause issues or crashes
    highlight = { enable = true },
  })
end

Error messages

Error executing vim.schedule lua callback: ...codecompanion.nvim/lua/codecompanion/strategies/chat.lua:308: attempt to index a nil value stack traceback: ...codecompanion.nvim/lua/codecompanion/strategies/chat.lua:308: in function 'cb' ...ainai/.repro/plugins/dressing.nvim/lua/dressing/util.lua:206: in function <...ainai/.repro/plugins/dressing.nvim/lua/dressing/util.lua:202>

Health check output

codecompanion: require("codecompanion.health").check()

codecompanion.nvim report

  • Log file: /Users/tarjeiromtveit/projects/private/supplychainai/.repro/state/nvim/codecompanion.log
  • OK plenary.nvim installed
  • OK nvim-treesitter installed
  • OK telescope.nvim installed
  • OK dressing.nvim installed
  • OK curl installed

Log output

Nothing in the log file

Describe the bug

The chat is not opening correctly. It is empty without any messages from the config (including the intro message) I removed the check in set_extmarks() function and added self.intro_message = false and is able to get the chat to open with the intro message.

Commit: 2ca47a1

Reproduce the bug

  1. :CodeCompanionActions
  2. -> Prompts -> Senior Developer
  3. Error message

Final checks

  • [X] I have made sure this issue exists in the latest version of the plugin
  • [X] I have tested with the minimal.lua config file above and still get the issue
  • [X] I have shared the contents of the log file

tarjeir avatar Aug 02 '24 21:08 tarjeir

Thanks for raising this. Should now be sorted.

olimorris avatar Aug 03 '24 07:08 olimorris