@@ -155,13 +155,6 @@ local function update_prompts(prompt, system_prompt)
155155 return system_prompt , result
156156end
157157
158- --- Append a string to the chat window.
159- --- @param str (string )
160- --- @param config CopilotChat.config
161- local function append (str , config )
162- state .chat :append (str )
163- end
164-
165158local function get_selection ()
166159 local bufnr = state .source .bufnr
167160 local winnr = state .source .winnr
@@ -463,9 +456,9 @@ function M.ask(prompt, config, source)
463456 local function on_error (err )
464457 log .error (vim .inspect (err ))
465458 vim .schedule (function ()
466- append (' \n\n ' .. config .error_header .. config .separator .. ' \n\n ' , config )
467- append (' ```\n ' .. get_error_message (err ) .. ' \n ```' , config )
468- append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' , config )
459+ state . chat : append (' \n\n ' .. config .error_header .. config .separator .. ' \n\n ' )
460+ state . chat : append (' ```\n ' .. get_error_message (err ) .. ' \n ```' )
461+ state . chat : append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' )
469462 state .chat :finish ()
470463 end )
471464 end
@@ -483,11 +476,11 @@ function M.ask(prompt, config, source)
483476 state .last_system_prompt = system_prompt
484477
485478 if state .copilot :stop () then
486- append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' , config )
479+ state . chat : append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' )
487480 end
488481
489- append (updated_prompt , config )
490- append (' \n\n ' .. config .answer_header .. config .separator .. ' \n\n ' , config )
482+ state . chat : append (updated_prompt )
483+ state . chat : append (' \n\n ' .. config .answer_header .. config .separator .. ' \n\n ' )
491484
492485 local selected_context = config .context
493486 local contexts = vim .tbl_keys (context .supported_contexts ())
@@ -535,7 +528,7 @@ function M.ask(prompt, config, source)
535528 temperature = config .temperature ,
536529 on_progress = function (token )
537530 vim .schedule (function ()
538- append (token , config )
531+ state . chat : append (token )
539532 end )
540533 end ,
541534 })
@@ -552,7 +545,7 @@ function M.ask(prompt, config, source)
552545 state .response = response
553546
554547 vim .schedule (function ()
555- append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' , config )
548+ state . chat : append (' \n\n ' .. config .question_header .. config .separator .. ' \n\n ' )
556549 if token_count and token_max_count and token_count > 0 then
557550 state .chat :finish (token_count .. ' /' .. token_max_count .. ' tokens used' )
558551 else
@@ -583,9 +576,9 @@ function M.stop(reset, config)
583576 if reset then
584577 state .chat :clear ()
585578 else
586- append (' \n\n ' , config )
579+ state . chat : append (' \n\n ' )
587580 end
588- append (M .config .question_header .. M .config .separator .. ' \n\n ' , config )
581+ state . chat : append (M .config .question_header .. M .config .separator .. ' \n\n ' )
589582 state .chat :finish ()
590583 end )
591584end
@@ -634,20 +627,20 @@ function M.load(name, history_path)
634627 for i , message in ipairs (history ) do
635628 if message .role == ' user' then
636629 if i > 1 then
637- append (' \n\n ' , state . config )
630+ state . chat : append (' \n\n ' )
638631 end
639- append (M .config .question_header .. M .config .separator .. ' \n\n ' , state . config )
640- append (message .content , state . config )
632+ state . chat : append (M .config .question_header .. M .config .separator .. ' \n\n ' )
633+ state . chat : append (message .content )
641634 elseif message .role == ' assistant' then
642- append (' \n\n ' .. M .config .answer_header .. M .config .separator .. ' \n\n ' , state . config )
643- append (message .content , state . config )
635+ state . chat : append (' \n\n ' .. M .config .answer_header .. M .config .separator .. ' \n\n ' )
636+ state . chat : append (message .content )
644637 end
645638 end
646639
647640 if # history > 0 then
648- append (' \n\n ' , state . config )
641+ state . chat : append (' \n\n ' )
649642 end
650- append (M .config .question_header .. M .config .separator .. ' \n\n ' , state . config )
643+ state . chat : append (M .config .question_header .. M .config .separator .. ' \n\n ' )
651644
652645 state .chat :finish ()
653646 M .open ()
@@ -993,7 +986,7 @@ function M.setup(config)
993986 })
994987 end
995988
996- append (M .config .question_header .. M .config .separator .. ' \n\n ' , M . config )
989+ state . chat : append (M .config .question_header .. M .config .separator .. ' \n\n ' )
997990 state .chat :finish ()
998991 end
999992 )
0 commit comments