File tree Expand file tree Collapse file tree
lua/codecompanion/interactions/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,13 +9,18 @@ local M = {}
99local api = vim .api
1010local fmt = string.format
1111
12- --- Create a new ACP connection for the given chat
12+ --- Establishes the connection, authenticates, creates a session and links the buffer
1313--- @param chat CodeCompanion.Chat The chat instance
1414--- @return boolean
1515function M .create_acp_connection (chat )
1616 local ACPHandler = require (" codecompanion.interactions.chat.acp.handler" )
1717 local handler = ACPHandler .new (chat )
18- return handler :ensure_connection ()
18+
19+ if not handler :ensure_connection () then
20+ return false
21+ end
22+
23+ return handler :ensure_session ()
1924end
2025
2126--- Format the given role without any separator
Original file line number Diff line number Diff line change @@ -731,15 +731,7 @@ function Chat:change_adapter(adapter)
731731 self .ui .adapter = self .adapter
732732
733733 if self .adapter .type == " acp" then
734- -- Ensure the ACP connection and session are created so users can select a model
735734 helpers .create_acp_connection (self )
736- if self .acp_connection then
737- self .acp_connection :ensure_session ()
738-
739- local acp_commands = require (" codecompanion.interactions.chat.acp.commands" )
740- acp_commands .link_buffer_to_session (self .bufnr , self .acp_connection .session_id )
741- end
742-
743735 helpers .remove_mcp_tools (self )
744736 end
745737
Original file line number Diff line number Diff line change @@ -54,7 +54,15 @@ function SlashCommand:execute()
5454 local command = Chat .adapter .commands [selected ]
5555 if command then
5656 Chat .adapter .commands .selected = command
57- Chat .acp_connection = nil
57+
58+ -- Disconnect the existing ACP process before starting a new one
59+ if Chat .acp_connection then
60+ pcall (function ()
61+ Chat .acp_connection :disconnect ()
62+ end )
63+ Chat .acp_connection = nil
64+ end
65+
5866 require (" codecompanion.interactions.chat.helpers" ).create_acp_connection (Chat )
5967 utils .notify (string.format (" Switched to `%s` command" , selected ))
6068 end
You can’t perform that action at this time.
0 commit comments