olimorris / codecompanion.nvim

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

[Bug] use_default_actions = false and use_default_prompts = false still create slash cmds and keybindings #105

Closed olimorris closed 2 months ago

olimorris commented 2 months ago

Discussed in https://github.com/olimorris/codecompanion.nvim/discussions/104

Originally posted by **isaksamsten** August 21, 2024 Hi! When setting the above "use_default_actions = false and use_default_promts = false" the actions and prompts still load as "slash" commands and keybindings. Is this a bug or intentional? Best, Isak
isaksamsten commented 2 months ago

Another question: is it outside the scope to disable the default prompts that are bundled with the plugin and just use your own? As it is now, you can either add your own and extend the default prompts (with use_default_prompts=true) and get keymappings and /command; or only use the prompts through CodeCompanionActions.

olimorris commented 2 months ago

So you should be able to set use_default_prompts = false and add your own default_prompts in your config.

This won't stop the slash cmds from being added (that's a bug I've just spotted), but it stops the default prompts from being added as we tag them with default_prompt = true in the config and never add them when we setup the action palette.

isaksamsten commented 2 months ago

To avoid keybindings to be added if use_default_prompts = false, something like this should go into prompt.lua:

---@return CodeCompanion.Prompts
function Prompts:setup()
  --Loop through the prompts
  local global_config = require("codecompanion").config
  for _, config in pairs(self.prompts) do
    if config.opts and config.opts.mapping then
      if not global_config.opts.use_default_prompts and config.opts.default_prompt then
        goto continue
      end
      if config.opts.modes and type(config.opts.modes) == "table" then
        for _, mode in ipairs(config.opts.modes) do
          map(config, mode)
        end
      else
        map(config, "n")
      end
    end
    ::continue::
  end
olimorris commented 2 months ago

Good spot. This has highlighted what a mess this default prompts and actions is currently

olimorris commented 2 months ago

@isaksamsten also fancy Pr'ing this?