From 8cbf6960960bf386d85badad99152bf021554986 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Wed, 8 Jan 2025 20:07:29 +0100 Subject: [PATCH] fix: use slash commands with `:CodeCompanion` cmd Users can now do `:CodeCompanion` and leverage slash commands in the input box --- lua/codecompanion/commands.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lua/codecompanion/commands.lua b/lua/codecompanion/commands.lua index d619fd4c..36799810 100644 --- a/lua/codecompanion/commands.lua +++ b/lua/codecompanion/commands.lua @@ -40,15 +40,7 @@ return { { cmd = "CodeCompanion", callback = function(opts) - if #vim.trim(opts.args or "") == 0 then - vim.ui.input({ prompt = config.display.action_palette.prompt }, function(input) - if #vim.trim(input or "") == 0 then - return - end - opts.args = input - codecompanion.inline(opts) - end) - else + local handler = function(opts) if string.sub(opts.args, 1, 1) == "/" then local user_prompt = nil -- Remove the leading slash @@ -86,6 +78,18 @@ return { codecompanion.inline(opts) end + + if #vim.trim(opts.args or "") == 0 then + vim.ui.input({ prompt = config.display.action_palette.prompt }, function(input) + if #vim.trim(input or "") == 0 then + return + end + opts.args = input + handler(opts) + end) + else + handler(opts) + end end, opts = { desc = "Use the CodeCompanion Inline Assistant",