Skip to content

Commit

Permalink
feat(chat): add CodeCompanionChatOpened event
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Dec 14, 2024
1 parent 2b269a7 commit fdfc640
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ The plugin sets the following highlight groups during setup:

The plugin fires many events during its lifecycle:

- `CodeCompanionChatOpened` - Fired after a chat has been opened
- `CodeCompanionChatClosed` - Fired after a chat has been closed
- `CodeCompanionChatAdapter` - Fired after the adapter has been set in the chat
- `CodeCompanionChatModel` - Fired after the model has been set in the chat
Expand Down
2 changes: 2 additions & 0 deletions lua/codecompanion/strategies/chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function Chat.new(args)
opts = args,
context = args.context,
cycle = 0,
from_prompt_library = args.from_prompt_library or false,
id = id,
last_role = args.last_role or config.constants.USER_ROLE,
messages = args.messages or {},
Expand Down Expand Up @@ -260,6 +261,7 @@ function Chat.new(args)
adapter = adapters.make_safe(self.adapter),
})
util.fire("ChatModel", { bufnr = self.bufnr, model = self.adapter.schema.model.default })
util.fire("ChatOpened", { bufnr = self.bufnr, from_prompt_library = self.from_prompt_library })

self:apply_settings(self.opts.settings)

Expand Down
1 change: 1 addition & 0 deletions lua/codecompanion/strategies/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function Strategies:chat()
adapter = self.selected.adapter,
context = self.context,
messages = messages,
from_prompt_library = self.selected.description and true or false,
auto_submit = (opts and opts.auto_submit) or false,
stop_context_insertion = (opts and self.selected.opts.stop_context_insertion) or false,
ignore_system_prompt = (opts and opts.ignore_system_prompt) or false,
Expand Down
2 changes: 2 additions & 0 deletions lua/codecompanion/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
---@field current_request table|nil The current request being executed
---@field current_tool table The current tool being executed
---@field cycle number The amount of times the chat has been sent to the LLM
---@field from_prompt_library? boolean Whether the chat was initiated from the prompt library-
---@field header_ns integer The namespace for the virtual text that appears in the header
---@field id integer The unique identifier for the chat
---@field intro_message? boolean Whether the welcome message has been shown
Expand All @@ -61,6 +62,7 @@
---@field adapter? CodeCompanion.Adapter The adapter used in this chat buffer
---@field auto_submit? boolean Automatically submit the chat when the chat buffer is created
---@field context? table Context of the buffer that the chat was initiated from
---@field from_prompt_library? boolean Whether the chat was initiated from the prompt library
---@field ignore_system_prompt? table Do not send the default system prompt with the request
---@field last_role? string The role of the last response in the chat buffer
---@field messages? table The messages to display in the chat buffer
Expand Down

0 comments on commit fdfc640

Please sign in to comment.