From 8c82cedc3d70255ec6ea0fdb348b3e931c435fba Mon Sep 17 00:00:00 2001 From: JonathanREmery Date: Wed, 25 Dec 2024 04:02:38 +0700 Subject: [PATCH] feat(chat): adding to chat initializes buffer if needed (#567) --- lua/codecompanion/init.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/codecompanion/init.lua b/lua/codecompanion/init.lua index b9186223..6ffd997e 100644 --- a/lua/codecompanion/init.lua +++ b/lua/codecompanion/init.lua @@ -89,18 +89,22 @@ end ---@param args table ---@return nil M.add = function(args) + local context = context_utils.get(api.nvim_get_current_buf(), args) + local content = table.concat(context.lines, "\n") + local chat = M.last_chat() if not chat then - return log:warn("No chat buffer found") + chat = M.chat() + + if not chat then + return log:warn("Could not create chat buffer") + end end if not config.opts.send_code then return log:warn("Sending of code to an LLM has been disabled") end - local context = context_utils.get(api.nvim_get_current_buf(), args) - local content = table.concat(context.lines, "\n") - chat:add_buf_message({ role = config.constants.USER_ROLE, content = "Here is some code from " @@ -111,6 +115,7 @@ M.add = function(args) .. content .. "\n```\n", }) + chat.ui:open() end ---Open a chat buffer and converse with an LLM