olimorris / codecompanion.nvim

✨ AI-powered coding, seamlessly in Neovim. Supports Anthropic, Copilot, Gemini, Ollama, OpenAI and xAI LLMs
MIT License
1.22k stars 88 forks source link

[Bug]: ui select panel not show when executing `CodeCompanionActions` in visual mode #375

Closed wenjinnn closed 3 weeks ago

wenjinnn commented 3 weeks ago

Your minimal.lua config

-- copy this to ~/.config/nvim-deps/init.lua
--  and start nvim with `NVIM_APPNAME=nvim-deps nvim -- ~/.config/nvim-deps/init.lua`
local path_package = vim.fn.stdpath('data') .. '/site/'
local mini_path = path_package .. 'pack/deps/start/mini.nvim'
if not vim.loop.fs_stat(mini_path) then
  vim.cmd('echo "Installing `mini.nvim`" | redraw')
  local clone_cmd = { 'git', 'clone', '--filter=blob:none', 'https://github.com/echasnovski/mini.nvim', mini_path }
  vim.fn.system(clone_cmd)
  vim.cmd('packadd mini.nvim | helptags ALL')
  vim.cmd('echo "Installed `mini.nvim`" | redraw')
end

-- Set up 'mini.deps' (customize to your liking)
require('mini.deps').setup({ path = { package = path_package } })

-- Use 'mini.deps'. `now()` and `later()` are helpers for a safe two-stage
-- startup and are optional.
local add = MiniDeps.add

add({
  source = "olimorris/codecompanion.nvim",
  depends = {
    { source = "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" },
    "nvim-lua/plenary.nvim",
    "hrsh7th/nvim-cmp"
  },
})

-- setup ui.select
require('mini.pick').setup()
vim.ui.select = MiniPick.ui_select

require("codecompanion").setup({
  display = {
    action_palette = {
      provider = "mini_pick",
    },
  },
  opts = {
    log_level = "DEBUG",
  },
})

-- 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 completion
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

No response

Log output

No error message appear in log file

Health check output

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

- Neovim version: 0.10.2
- Log file: /home/wenjin/.local/state/nvim-deps/codecompanion.log

Plugins:
- OK plenary.nvim installed
- OK nvim-treesitter installed
- OK nvim-cmp installed
- WARNING telescope.nvim not found
- WARNING dressing.nvim not found

Tree-sitter parsers:
- OK markdown parser installed
- OK yaml parser installed

Libraries:
- OK curl installed

Describe the bug

Select some text in visual mode and execute :'<,'>CodeCompanionActions, not showing ui select panel

Reproduce the bug

  1. Select some text in visual mode
  2. Type :'<,'>CodeCompanionActions and execute

Final checks

olimorris commented 3 weeks ago

Your minimal file isn't working. It's causing me the following error:

Error detected while processing /Users/Oli/Code/Neovim/codecompanion.nvim/minimal2.lua:
E5113: Error while calling lua chunk: vim/_editor.lua:0: /Users/Oli/Code/Neovim/codecompanion.nvim/minimal2.lua..nvim_exec2() called at /Users/Oli/Code/Neovim/codecompanion.nvim/minimal2.lua:0: Vim(packadd):E919: Directory not found in 'packpath':"pack/*/opt/mini.nvim"
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        /Users/Oli/Code/Neovim/codecompanion.nvim/minimal2.lua:9: in main chunk
olimorris commented 3 weeks ago

I can confirm this works with the minimal.lua file provided in the repo:

2024-10-28 09_31_41 - WezTerm

I opened Neovim with nvim --clean -u minimal.lua minimal.lua

wenjinnn commented 3 weeks ago

Sorry for that, look's like mini.deps have some issue that open with nvim --clean. I made another minimal.lua base on readme template and reproduce it again with nvim --clean -u minimal.lua minimal.lua, please note that I'm using mini.pick:

---@diagnostic disable: missing-fields

--NOTE: Set config path to enable the copilot adapter to work.
--It will search the follwoing paths for the for copilot 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" },
      { "hrsh7th/nvim-cmp" },
      { "echasnovski/mini.pick" },
    },
    opts = {
      --Refer to: https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua
      display = {
        action_palette = {
          provider = "mini_pick",
        },
      },
      opts = {
        log_level = "DEBUG",
      },
    },
  },
}

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 completion
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

-- setup ui.select
require('mini.pick').setup()
vim.ui.select = MiniPick.ui_select
olimorris commented 3 weeks ago

Should have spotted this sooner. Mini.Pick isn't supported for the Action Palette unfortunately. We just support a default which is vim.ui.select or Telescope.

Would be more than happy to support Mini.Pick via a PR though.

sohanemon commented 2 weeks ago

Should have spotted this sooner. Mini.Pick isn't supported for the Action Palette unfortunately. We just support a default which is vim.ui.select or Telescope.

Would be more than happy to support Mini.Pick via a PR though.

https://github.com/user-attachments/assets/7829e297-2f47-4326-ae99-2ed92afe15bd

I think this issue also persists with fzf-lua