1+ local log = require (" codecompanion-spinner.log" )
12local Spinner = require (" codecompanion-spinner.spinner" )
23
34local M = {}
@@ -9,6 +10,7 @@ M.setup = function()
910 vim .api .nvim_create_autocmd (" User" , {
1011 pattern = " CodeCompanionChatCreated" ,
1112 callback = function (args )
13+ log .debug (" CodeCompanionChatCreated" )
1214 local chat_id = args .data .id
1315 assert (spinners [chat_id ] == nil )
1416 active_spinner = Spinner :new (chat_id , args .buf )
@@ -19,6 +21,7 @@ M.setup = function()
1921 vim .api .nvim_create_autocmd (" User" , {
2022 pattern = " CodeCompanionChatClosed" ,
2123 callback = function (args )
24+ log .debug (" CodeCompanionChatClosed" )
2225 local chat_id = args .data .id
2326 if spinners [chat_id ] then
2427 spinners [chat_id ]:stop ()
@@ -30,6 +33,8 @@ M.setup = function()
3033 vim .api .nvim_create_autocmd (" User" , {
3134 pattern = " CodeCompanionChatOpened" ,
3235 callback = function (args )
36+ log .debug (" CodeCompanionChatOpened" )
37+
3338 local spinner = spinners [args .data .id ]
3439
3540 -- When a new chat is created, this event is triggered but no spinner is
@@ -47,6 +52,7 @@ M.setup = function()
4752 vim .api .nvim_create_autocmd (" User" , {
4853 pattern = " CodeCompanionChatHidden" ,
4954 callback = function (args )
55+ log .debug (" CodeCompanionChatHidden" )
5056 local spinner = spinners [args .data .id ]
5157 spinner :disable ()
5258 end ,
@@ -55,6 +61,7 @@ M.setup = function()
5561 vim .api .nvim_create_autocmd (" User" , {
5662 pattern = " CodeCompanionRequestStarted" ,
5763 callback = function (args )
64+ log .debug (" CodeCompanionRequestStarted" )
5865 assert (active_spinner )
5966 active_spinner :start (args .data .id )
6067 end ,
@@ -63,21 +70,18 @@ M.setup = function()
6370 vim .api .nvim_create_autocmd (" User" , {
6471 pattern = " CodeCompanionRequestFinished" ,
6572 callback = function (args )
73+ log .debug (" CodeCompanionRequestFinished" )
74+
75+ -- Search for the spinner is handling the request.
76+ -- Note: If the chat was stopped, the spinner was deleted.
77+ -- In that case, no spinner will be found.
6678 local request_id = args .data .id
6779 for _ , spinner in pairs (spinners ) do
6880 if spinner .request_id == request_id then
6981 spinner :stop ()
70- return
82+ break
7183 end
7284 end
73- error (" No spinner found for request ID: " .. request_id )
74- end ,
75- })
76-
77- vim .api .nvim_create_autocmd (" User" , {
78- pattern = " CodeCompanionChatStopped" ,
79- callback = function (args )
80- spinners [args .data .id ]:stop ()
8185 end ,
8286 })
8387end
0 commit comments