@@ -4,106 +4,73 @@ local telescope_pickers = require('telescope.pickers')
44local finders = require (' telescope.finders' )
55local themes = require (' telescope.themes' )
66local conf = require (' telescope.config' ).values
7- local utils = require (' CopilotChat.utils' )
7+ local select = require (' CopilotChat.select' )
8+ local chat = require (' CopilotChat' )
89
910local help_actions = {}
1011local user_prompt_actions = {}
1112
1213local function generate_fix_diagnostic_prompt ()
13- local diagnostic = utils . get_diagnostics ()
14- if diagnostic == ' No diagnostics available ' then
15- return diagnostic
14+ local diagnostic = select . diagnostics ()
15+ if not diagnostic then
16+ return ' No diagnostics available '
1617 end
1718
18- local file_name = vim .fn .expand (' %:t' )
19- local line_number = vim .fn .line (' .' )
2019 return ' Please assist with fixing the following diagnostic issue in file: "'
21- .. file_name
22- .. ' :'
23- .. line_number
24- .. ' ". '
25- .. diagnostic
20+ .. diagnostic .prompt_extra
2621end
2722
2823local function generate_explain_diagnostic_prompt ()
29- local diagnostic = utils . get_diagnostics ()
30- if diagnostic == ' No diagnostics available ' then
31- return diagnostic
24+ local diagnostic = select . diagnostics ()
25+ if not diagnostic then
26+ return ' No diagnostics available '
3227 end
3328
34- local file_name = vim .fn .expand (' %:t' )
35- local line_number = vim .fn .line (' .' )
36- return ' Please explain the following diagnostic issue in file: "'
37- .. file_name
38- .. ' :'
39- .. line_number
40- .. ' ". '
41- .. diagnostic
29+ return ' Please explain the following diagnostic issue in file: "' .. diagnostic .prompt_extra
4230end
4331
4432--- Help command for telescope picker
45- --- This will copy all the lines in the buffer to the unnamed register
33+ --- This will send whole buffer to copilot
4634--- Then will send the diagnostic to copilot chat
47- --- @param prefix string
48- local function diagnostic_help_command (prefix )
49- if prefix == nil then
50- prefix = ' '
51- else
52- prefix = prefix .. ' '
53- end
54-
55- return function (prompt_bufnr , _ )
56- actions .select_default :replace (function ()
57- actions .close (prompt_bufnr )
58- local selection = action_state .get_selected_entry ()
59-
60- -- Select all the lines in the buffer to uname register
61- vim .cmd (' normal! ggVG"*y' )
62-
63- -- Get value from the help_actions and execute the command
64- local value = ' '
65- for _ , action in pairs (help_actions ) do
66- if action .name == selection [1 ] then
67- value = action .label
68- break
69- end
35+ local function diagnostic_help_command (prompt_bufnr , _ )
36+ actions .select_default :replace (function ()
37+ actions .close (prompt_bufnr )
38+ local selection = action_state .get_selected_entry ()
39+
40+ -- Get value from the help_actions and execute the command
41+ local value = ' '
42+ for _ , action in pairs (help_actions ) do
43+ if action .name == selection [1 ] then
44+ value = action .label
45+ break
7046 end
47+ end
7148
72- vim .cmd (prefix .. value )
73- end )
74- return true
75- end
49+ chat .ask (value , { selection = select .buffer })
50+ end )
51+ return true
7652end
7753
7854--- Prompt command for telescope picker
7955--- This will show all the user prompts in the telescope picker
8056--- Then will execute the command selected by the user
81- --- @param prefix string
82- local function generate_prompt_command (prefix )
83- if prefix == nil then
84- prefix = ' '
85- else
86- prefix = prefix .. ' '
87- end
88-
89- return function (prompt_bufnr , _ )
90- actions .select_default :replace (function ()
91- actions .close (prompt_bufnr )
92- local selection = action_state .get_selected_entry ()
93-
94- -- Get value from the prompt_actions and execute the command
95- local value = ' '
96- for _ , action in pairs (user_prompt_actions ) do
97- if action .name == selection [1 ] then
98- value = action .label
99- break
100- end
57+ local function generate_prompt_command (prompt_bufnr , _ )
58+ actions .select_default :replace (function ()
59+ actions .close (prompt_bufnr )
60+ local selection = action_state .get_selected_entry ()
61+
62+ -- Get value from the prompt_actions and execute the command
63+ local value = ' '
64+ for _ , action in pairs (user_prompt_actions ) do
65+ if action .name == selection [1 ] then
66+ value = action .label
67+ break
10168 end
69+ end
10270
103- vim .cmd (prefix .. value )
104- end )
105- return true
106- end
71+ chat .ask (value )
72+ end )
73+ return true
10774end
10875
10976local function show_help_actions ()
@@ -136,25 +103,18 @@ local function show_help_actions()
136103 results = action_names ,
137104 }),
138105 sorter = conf .generic_sorter (opts ),
139- attach_mappings = diagnostic_help_command ( ' CopilotChat ' ) ,
106+ attach_mappings = diagnostic_help_command ,
140107 })
141108 :find ()
142109end
143110
144111--- Show prompt actions
145- --- @param is_in_visual_mode boolean ?
146- local function show_prompt_actions (is_in_visual_mode )
112+ local function show_prompt_actions ()
147113 -- Convert user prompts to a table of actions
148114 user_prompt_actions = {}
149115
150- for key , prompt in pairs (vim .g .copilot_chat_user_prompts ) do
151- table.insert (user_prompt_actions , { name = key , label = prompt })
152- end
153-
154- local cmd = ' CopilotChat'
155-
156- if is_in_visual_mode then
157- cmd = " '<,'>CopilotChatVisual"
116+ for key , prompt in pairs (chat .get_prompts (true )) do
117+ table.insert (user_prompt_actions , { name = key , label = prompt .prompt })
158118 end
159119
160120 -- Show the menu with telescope pickers
@@ -170,7 +130,7 @@ local function show_prompt_actions(is_in_visual_mode)
170130 results = action_names ,
171131 }),
172132 sorter = conf .generic_sorter (opts ),
173- attach_mappings = generate_prompt_command ( cmd ) ,
133+ attach_mappings = generate_prompt_command ,
174134 })
175135 :find ()
176136end
0 commit comments