Skip to content

Commit

Permalink
feat(chat): adding to chat initializes buffer if needed (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanREmery authored Dec 24, 2024
1 parent d4b71b4 commit 8c82ced
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lua/codecompanion/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -111,6 +115,7 @@ M.add = function(args)
.. content
.. "\n```\n",
})
chat.ui:open()
end

---Open a chat buffer and converse with an LLM
Expand Down

0 comments on commit 8c82ced

Please sign in to comment.