Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error processing InsertLeave Autocommands with show_settings #915

Closed
3 tasks done
bashtoni opened this issue Feb 14, 2025 · 2 comments
Closed
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@bashtoni
Copy link
Contributor

Your minimal.lua config

---@diagnostic disable: missing-fields

--[[
NOTE: Set the config path to enable the copilot adapter to work.
It will search the following paths for a token:
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/hosts.json"
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/apps.json"
--]]
vim.env["CODECOMPANION_TOKEN_PATH"] = vim.fn.expand("~/.config")

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

-- Your CodeCompanion setup
local plugins = {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
      { "nvim-lua/plenary.nvim" },
      -- Test with blink.cmp
      {
        "saghen/blink.cmp",
        lazy = false,
        version = "*",
        opts = {
          keymap = {
            preset = "enter",
            ["<S-Tab>"] = { "select_prev", "fallback" },
            ["<Tab>"] = { "select_next", "fallback" },
          },
          sources = {
            default = { "lsp", "path", "buffer", "codecompanion" },
            cmdline = {}, -- Disable sources for command-line mode
          },
        },
      },
      -- Test with nvim-cmp
      -- { "hrsh7th/nvim-cmp" },
    },
    opts = {
      --Refer to: https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua
      strategies = {
        --NOTE: Change the adapter as required
        chat = { adapter = "copilot" },
        inline = { adapter = "copilot" },
      },
      opts = {
        log_level = "DEBUG",
      },
      display = {
        chat = {
          show_settings = true,
        },
      },
    },
  },
}

require("lazy.minit").repro({ spec = plugins })

-- Setup Tree-sitter
local ts_status, treesitter = pcall(require, "nvim-treesitter.configs")
if ts_status then
  treesitter.setup({
    ensure_installed = { "lua", "markdown", "markdown_inline", "yaml" },
    highlight = { enable = true },
  })
end

-- Setup nvim-cmp
-- local cmp_status, cmp = pcall(require, "cmp")
-- if cmp_status then
--   cmp.setup({
--     mapping = cmp.mapping.preset.insert({
--       ["<C-b>"] = cmp.mapping.scroll_docs(-4),
--       ["<C-f>"] = cmp.mapping.scroll_docs(4),
--       ["<C-Space>"] = cmp.mapping.complete(),
--       ["<C-e>"] = cmp.mapping.abort(),
--       ["<CR>"] = cmp.mapping.confirm({ select = true }),
--       -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
--     }),
--   })
-- end

Error messages

Error detected while processing InsertLeave Autocommands for "<buffer=4>":
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:190: bad argument #3 to 'f' (invalid buffer h
andle: 3)
stack traceback:
        [C]: in function 'f'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:190: in function 'tcall'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:361: in function '_parse_regions'
        /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:439: in function 'parse'
        ...ompanion.nvim/lua/codecompanion/strategies/chat/init.lua:107: in function 'ts_parse_settings'
        ...ompanion.nvim/lua/codecompanion/strategies/chat/init.lua:376: in function <...ompanion.nvim/lua/codecompanion/strategies/cha
t/init.lua:375>

Log output

Error happens before log is created.

Describe the bug

Error when leaving insert mode on the second CodeCompanion buffer when show_settings is true.
Tested on Fedora 41.

Reproduce the bug

  1. :CodeCompanionChat
  2. Enter insert mode
  3. Escape to normal mode
  4. Close window with ctrl+c
  5. :CodeCompanionChat
  6. Enter insert mode
  7. Escape to normal mode

Adapter and model

copilot

Final checks

  • I have made sure this issue exists in the latest version of the plugin
  • I have tested with the minimal.lua file from above and have shared this
  • I have shared the contents of the log file
@bashtoni bashtoni added the bug Something isn't working label Feb 14, 2025
Copy link
Contributor

Important

If your issue does NOT contain a valid minimal.lua then this issue may be closed without a response.
Thanks for respecting my time and efforts.

Thanks @bashtoni. I'll get to this as soon as I can.

In the meantime, please ensure:

  • This is a plugin related issue and not an issue with your configuration
  • You've searched for similar issues (try the discussions too)
  • You've checked out the documentation
  • The issue title is accurate
  • There is a valid minimal.lua file included so I can try and recreate the issue

@olimorris
Copy link
Owner

Thanks for catching this. Now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants