@@ -13,7 +13,6 @@ local Split = require("nui.split")
1313--- @field private _initialized boolean Whether the sidebar has been initialized
1414--- @field private _current_response_buffer string Buffer for accumulating streaming response
1515--- @field private _is_streaming boolean Whether we ' re currently receiving a streaming response
16- --- @field private _last_assistant_line integer Line number of the last assistant message
1716--- @field private _usage_info string Current usage information
1817--- @field private _last_user_message string Last user message to avoid duplicates
1918--- @field private _current_tool_call table Current tool call being accumulated
@@ -48,7 +47,6 @@ function M.new(id, mediator)
4847 instance ._initialized = false
4948 instance ._current_response_buffer = " "
5049 instance ._is_streaming = false
51- instance ._last_assistant_line = 0
5250 instance ._usage_info = " "
5351 instance ._last_user_message = " "
5452 instance ._current_tool_call = nil
@@ -182,7 +180,6 @@ function M:reset()
182180 self ._initialized = false
183181 self ._is_streaming = false
184182 self ._current_response_buffer = " "
185- self ._last_assistant_line = 0
186183 self ._usage_info = " "
187184 self ._last_user_message = " "
188185 self ._current_tool_call = nil
@@ -458,6 +455,20 @@ function M:_setup_input_events(container)
458455 end
459456 end
460457
458+ -- contexts line modified, restore
459+ if # contexts_line > # self ._contexts_placeholder_line then
460+ local placeholders = vim .split (contexts_line , " @" , { plain = true , trimempty = false })
461+
462+ vim .notify (" placeholders: " .. vim .inspect (placeholders ), vim .log .levels .DEBUG )
463+
464+ if # placeholders [# placeholders ] < 1 then
465+ self :_update_input_display ()
466+ return
467+ end
468+
469+ return
470+ end
471+
461472 self :_update_input_display ()
462473 return
463474 end
@@ -1146,7 +1157,6 @@ function M:_handle_streaming_text(text)
11461157
11471158 -- Add assistant placeholder and track its start line
11481159 self :_add_message (" assistant" , " " )
1149- self ._last_assistant_line = start_line
11501160
11511161 -- Track placeholder with an extmark independent of header content
11521162 self .extmarks = self .extmarks or {}
@@ -1176,8 +1186,8 @@ end
11761186--- @param content string
11771187function M :_update_streaming_message (content )
11781188 local chat = self .containers .chat
1179- if not chat or self . _last_assistant_line == 0 then
1180- Logger .notify ( " Cannot update - no chat or no assistant line " , vim . log . levels . ERROR )
1189+ if not chat then
1190+ Logger .debug ( " DEBUG: Cannot update - no chat" )
11811191 return
11821192 end
11831193
@@ -1201,15 +1211,15 @@ function M:_update_streaming_message(content)
12011211 local content_lines = Utils .split_lines (content )
12021212
12031213 -- Resolve assistant start line using extmark if available
1204- local start_line = self . _last_assistant_line
1214+ local start_line = 0
12051215 if self .extmarks and self .extmarks .assistant and self .extmarks .assistant ._id then
12061216 local pos = vim .api .nvim_buf_get_extmark_by_id (chat .bufnr , self .extmarks .assistant ._ns , self .extmarks .assistant ._id , {})
12071217 if pos and pos [1 ] then
12081218 start_line = pos [1 ] + 1
12091219 end
12101220 end
12111221
1212- Logger .debug (" DEBUG: Assistant line: " .. tostring ( self . _last_assistant_line ) .. " , start_line : " .. tostring (start_line ))
1222+ Logger .debug (" DEBUG: Start Line : " .. tostring (start_line ))
12131223 Logger .debug (" DEBUG: Content lines: " .. # content_lines )
12141224
12151225 -- Replace assistant content directly
@@ -1312,7 +1322,6 @@ function M:_add_message(role, content)
13121322 -- Auto-scroll to bottom after adding new message
13131323 self :_scroll_to_bottom ()
13141324 end )
1315- self ._last_assistant_line = self :_get_last_message_line ()
13161325end
13171326
13181327function M :_finalize_streaming_response ()
@@ -1322,7 +1331,6 @@ function M:_finalize_streaming_response()
13221331
13231332 self ._is_streaming = false
13241333 self ._current_response_buffer = " "
1325- self ._last_assistant_line = 0
13261334 self ._response_start_time = 0
13271335
13281336 -- Clear assistant placeholder tracking extmark
@@ -1363,32 +1371,6 @@ function M:_scroll_to_bottom()
13631371 end , 10 ) -- Reduced delay for faster streaming response
13641372end
13651373
1366- function M :_get_last_message_line ()
1367- local chat = self .containers .chat
1368- if not chat then
1369- return 0
1370- end
1371-
1372- local lines = vim .api .nvim_buf_get_lines (chat .bufnr , 0 , - 1 , false )
1373- local assistant_header_lines = Utils .split_lines (self ._headers .assistant )
1374- local assistant_header = " "
1375-
1376- for i = # assistant_header_lines , 1 , - 1 do
1377- if assistant_header_lines [i ] and assistant_header_lines [i ] ~= " " then
1378- assistant_header = assistant_header_lines [i ]
1379- break
1380- end
1381- end
1382-
1383- for i = # lines , 1 , - 1 do
1384- local line = lines [i ]
1385- if line and line :sub (1 , # assistant_header ) == assistant_header then
1386- return i
1387- end
1388- end
1389- return 0
1390- end
1391-
13921374--- @param bufnr integer
13931375--- @param callback function
13941376function M :_safe_buffer_update (bufnr , callback )
0 commit comments