11local async = require (' plenary.async' )
2- local copilot = require (' CopilotChat' )
32local client = require (' CopilotChat.client' )
43local constants = require (' CopilotChat.constants' )
54local select = require (' CopilotChat.select' )
65local utils = require (' CopilotChat.utils' )
7- local diff = require (' CopilotChat.utils.diff' )
86local files = require (' CopilotChat.utils.files' )
97
108--- Prepare a buffer for applying a diff
@@ -77,22 +75,23 @@ return {
7775 normal = ' q' ,
7876 insert = ' <C-c>' ,
7977 callback = function ()
80- copilot .close ()
78+ require ( ' CopilotChat ' ) .close ()
8179 end ,
8280 },
8381
8482 reset = {
8583 normal = ' <C-l>' ,
8684 insert = ' <C-l>' ,
8785 callback = function ()
88- copilot .reset ()
86+ require ( ' CopilotChat ' ) .reset ()
8987 end ,
9088 },
9189
9290 submit_prompt = {
9391 normal = ' <CR>' ,
9492 insert = ' <C-s>' ,
9593 callback = function ()
94+ local copilot = require (' CopilotChat' )
9695 local message = copilot .chat :get_message (constants .ROLE .USER , true )
9796 if not message then
9897 return
@@ -106,7 +105,10 @@ return {
106105 normal = ' <C-y>' ,
107106 insert = ' <C-y>' ,
108107 callback = function (source )
109- local block = copilot .chat :get_block (constants .ROLE .ASSISTANT , true )
108+ local chat = require (' CopilotChat' ).chat
109+ local diff = require (' CopilotChat.utils.diff' )
110+
111+ local block = chat :get_block (constants .ROLE .ASSISTANT , true )
110112 if not block then
111113 return
112114 end
@@ -127,7 +129,10 @@ return {
127129 jump_to_diff = {
128130 normal = ' gj' ,
129131 callback = function (source )
130- local block = copilot .chat :get_block (constants .ROLE .ASSISTANT , true )
132+ local chat = require (' CopilotChat' ).chat
133+ local diff = require (' CopilotChat.utils.diff' )
134+
135+ local block = chat :get_block (constants .ROLE .ASSISTANT , true )
131136 if not block then
132137 return
133138 end
@@ -147,19 +152,24 @@ return {
147152 normal = ' gy' ,
148153 register = ' "' , -- Default register to use for yanking
149154 callback = function ()
150- local block = copilot .chat :get_block (constants .ROLE .ASSISTANT , true )
155+ local config = require (' CopilotChat.config' )
156+ local chat = require (' CopilotChat' ).chat
157+ local block = chat :get_block (constants .ROLE .ASSISTANT , true )
151158 if not block then
152159 return
153160 end
154161
155- vim .fn .setreg (copilot . config .mappings .yank_diff .register , block .content )
162+ vim .fn .setreg (config .mappings .yank_diff .register , block .content )
156163 end ,
157164 },
158165
159166 show_diff = {
160167 normal = ' gd' ,
161168 callback = function (source )
162- local block = copilot .chat :get_block (constants .ROLE .ASSISTANT , true )
169+ local chat = require (' CopilotChat' ).chat
170+ local diff = require (' CopilotChat.utils.diff' )
171+
172+ local block = chat :get_block (constants .ROLE .ASSISTANT , true )
163173 if not block then
164174 return
165175 end
@@ -168,7 +178,7 @@ return {
168178 local bufnr = prepare_diff_buffer (path , source )
169179
170180 -- Collect all blocks for the same filename
171- local message = copilot . chat :get_message (constants .ROLE .ASSISTANT , true )
181+ local message = chat :get_message (constants .ROLE .ASSISTANT , true )
172182 local blocks = {}
173183 if message and message .section and message .section .blocks then
174184 for _ , b in ipairs (message .section .blocks ) do
@@ -196,26 +206,27 @@ return {
196206 vim .cmd (' diffthis' )
197207 end )
198208
199- vim .api .nvim_win_call (copilot . chat .winnr , function ()
209+ vim .api .nvim_win_call (chat .winnr , function ()
200210 vim .cmd (' diffthis' )
201211 end )
202212 end
203213
204214 opts .on_hide = function ()
205- vim .api .nvim_win_call (copilot . chat .winnr , function ()
215+ vim .api .nvim_win_call (chat .winnr , function ()
206216 vim .cmd (' diffoff' )
207217 end )
208218 end
209219
210- copilot . chat :overlay (opts )
220+ chat :overlay (opts )
211221 end ,
212222 },
213223
214224 quickfix_diffs = {
215225 normal = ' gqd' ,
216226 callback = function ()
227+ local chat = require (' CopilotChat' ).chat
217228 local items = {}
218- local messages = copilot . chat :get_messages ()
229+ local messages = chat :get_messages ()
219230 for _ , message in ipairs (messages ) do
220231 if message .section then
221232 for _ , block in ipairs (message .section .blocks ) do
@@ -225,7 +236,7 @@ return {
225236 end
226237
227238 table.insert (items , {
228- bufnr = copilot . chat .bufnr ,
239+ bufnr = chat .bufnr ,
229240 lnum = block .start_line ,
230241 end_lnum = block .end_line ,
231242 text = text ,
@@ -242,8 +253,9 @@ return {
242253 quickfix_answers = {
243254 normal = ' gqa' ,
244255 callback = function ()
256+ local chat = require (' CopilotChat' ).chat
245257 local items = {}
246- local messages = copilot . chat :get_messages ()
258+ local messages = chat :get_messages ()
247259 for i , message in ipairs (messages ) do
248260 if message .section and message .role == constants .ROLE .ASSISTANT then
249261 local prev_message = messages [i - 1 ]
@@ -253,7 +265,7 @@ return {
253265 end
254266
255267 table.insert (items , {
256- bufnr = copilot . chat .bufnr ,
268+ bufnr = chat .bufnr ,
257269 lnum = message .section .start_line ,
258270 end_lnum = message .section .end_line ,
259271 text = text ,
@@ -269,28 +281,31 @@ return {
269281 show_info = {
270282 normal = ' gc' ,
271283 callback = function (source )
272- local message = copilot .chat :get_message (constants .ROLE .USER , true )
284+ local chat = require (' CopilotChat' ).chat
285+ local prompts = require (' CopilotChat.prompts' )
286+
287+ local message = chat :get_message (constants .ROLE .USER , true )
273288 if not message then
274289 return
275290 end
276291
277292 local lines = {}
278293
279294 async .run (function ()
280- local config , prompt = copilot .resolve_prompt (message .content )
295+ local config , prompt = prompts .resolve_prompt (message .content )
281296 local system_prompt = config .system_prompt
282- local resolved_resources = copilot .resolve_functions (prompt , config )
283- local selected_tools = copilot .resolve_tools (prompt , config )
284- local selected_model = copilot .resolve_model (prompt , config )
297+ local resolved_resources = prompts .resolve_functions (prompt , config )
298+ local selected_tools = prompts .resolve_tools (prompt , config )
299+ local selected_model = prompts .resolve_model (prompt , config )
285300 local infos = client :info ()
286301
287302 selected_tools = vim .tbl_map (function (tool )
288303 return tool .name
289304 end , selected_tools )
290305
291306 utils .schedule_main ()
292- table.insert (lines , ' **Logs**: `' .. copilot . config .log_path .. ' `' )
293- table.insert (lines , ' **History**: `' .. copilot . config .history_path .. ' `' )
307+ table.insert (lines , ' **Logs**: `' .. config .log_path .. ' `' )
308+ table.insert (lines , ' **History**: `' .. config .history_path .. ' `' )
294309 table.insert (lines , ' ' )
295310
296311 for provider , infolines in pairs (infos ) do
@@ -368,7 +383,7 @@ return {
368383 table.insert (lines , ' ' )
369384 end
370385
371- copilot . chat :overlay ({
386+ chat :overlay ({
372387 text = vim .trim (table.concat (lines , ' \n ' )) .. ' \n ' ,
373388 })
374389 end )
@@ -378,6 +393,9 @@ return {
378393 show_help = {
379394 normal = ' gh' ,
380395 callback = function ()
396+ local config = require (' CopilotChat.config' )
397+ local chat = require (' CopilotChat' ).chat
398+
381399 local chat_help = ' **`Special tokens`**\n '
382400 chat_help = chat_help .. ' `@<function>` to share function\n '
383401 chat_help = chat_help .. ' `#<function>` to add resource\n '
@@ -387,22 +405,22 @@ return {
387405 chat_help = chat_help .. ' `> <text>` to make a sticky prompt (copied to next prompt)\n '
388406
389407 chat_help = chat_help .. ' \n **`Mappings`**\n '
390- local chat_keys = vim .tbl_keys (copilot . config .mappings )
408+ local chat_keys = vim .tbl_keys (config .mappings )
391409 table.sort (chat_keys , function (a , b )
392- a = copilot . config .mappings [a ]
410+ a = config .mappings [a ]
393411 a = a and (a .normal or a .insert ) or ' '
394- b = copilot . config .mappings [b ]
412+ b = config .mappings [b ]
395413 b = b and (b .normal or b .insert ) or ' '
396414 return a < b
397415 end )
398416 for _ , name in ipairs (chat_keys ) do
399- local info = utils .key_to_info (name , copilot . config .mappings [name ], ' `' )
417+ local info = utils .key_to_info (name , config .mappings [name ], ' `' )
400418 if info ~= ' ' then
401419 chat_help = chat_help .. info .. ' \n '
402420 end
403421 end
404422
405- copilot . chat :overlay ({
423+ chat :overlay ({
406424 text = chat_help ,
407425 })
408426 end ,
0 commit comments