@@ -281,6 +281,34 @@ local function resolve_embeddings(prompt, config)
281281 return embeddings :values (), prompt
282282end
283283
284+ local function resolve_agent (prompt , config )
285+ local agents = vim .tbl_keys (state .copilot :list_agents ())
286+ local selected_agent = config .agent
287+ prompt = prompt :gsub (' @' .. WORD , function (match )
288+ if vim .tbl_contains (agents , match ) then
289+ selected_agent = match
290+ return ' '
291+ end
292+ return ' @' .. match
293+ end )
294+
295+ return selected_agent , prompt
296+ end
297+
298+ local function resolve_model (prompt , config )
299+ local models = vim .tbl_keys (state .copilot :list_models ())
300+ local selected_model = config .model
301+ prompt = prompt :gsub (' %$' .. WORD , function (match )
302+ if vim .tbl_contains (models , match ) then
303+ selected_model = match
304+ return ' '
305+ end
306+ return ' $' .. match
307+ end )
308+
309+ return selected_model , prompt
310+ end
311+
284312--- @param start_of_chat boolean ?
285313local function finish (start_of_chat )
286314 if not start_of_chat then
@@ -684,28 +712,9 @@ function M.ask(prompt, config)
684712 local selection = get_selection (config )
685713
686714 local ok , err = pcall (async .run , function ()
687- local embeddings , embedded_prompt = resolve_embeddings (prompt , config )
688- prompt = embedded_prompt
689-
690- local agents = vim .tbl_keys (state .copilot :list_agents ())
691- local selected_agent = config .agent
692- prompt = prompt :gsub (' @' .. WORD , function (match )
693- if vim .tbl_contains (agents , match ) then
694- selected_agent = match
695- return ' '
696- end
697- return ' @' .. match
698- end )
699-
700- local models = vim .tbl_keys (state .copilot :list_models ())
701- local selected_model = config .model
702- prompt = prompt :gsub (' %$' .. WORD , function (match )
703- if vim .tbl_contains (models , match ) then
704- selected_model = match
705- return ' '
706- end
707- return ' $' .. match
708- end )
715+ local embeddings , prompt = resolve_embeddings (prompt , config )
716+ local selected_agent , prompt = resolve_agent (prompt , config )
717+ local selected_model , prompt = resolve_model (prompt , config )
709718
710719 local has_output = false
711720 local query_ok , filtered_embeddings =
@@ -875,6 +884,14 @@ function M.setup(config)
875884 normal = key ,
876885 }
877886 end
887+
888+ if name == ' show_system_prompt' then
889+ utils .deprecate (' config.mappings.' .. name , ' config.mappings.show_info' )
890+ end
891+
892+ if name == ' show_user_context' or name == ' show_user_selection' then
893+ utils .deprecate (' config.mappings.' .. name , ' config.mappings.show_context' )
894+ end
878895 end
879896 end
880897
@@ -1137,52 +1154,103 @@ function M.setup(config)
11371154 state .diff :show (diff , state .chat .winnr )
11381155 end )
11391156
1140- map_key (' show_system_prompt ' , bufnr , function ()
1157+ map_key (' show_info ' , bufnr , function ()
11411158 local section = state .chat :get_closest_section ()
1142- local system_prompt = state .chat .config .system_prompt
1143- if section and not section .answer then
1144- _ , system_prompt = resolve_prompts (section .content , system_prompt )
1145- end
1146- if not system_prompt then
1159+ if not section or section .answer then
11471160 return
11481161 end
11491162
1150- state .overlay :show (vim .trim (system_prompt ) .. ' \n ' , state .chat .winnr , ' markdown' )
1163+ local lines = {}
1164+ local config = state .chat .config
1165+ local prompt , system_prompt = resolve_prompts (section .content , config .system_prompt )
1166+
1167+ async .run (function ()
1168+ local selected_agent = resolve_agent (prompt , config )
1169+ local selected_model = resolve_model (prompt , config )
1170+
1171+ if selected_model then
1172+ table.insert (lines , ' **Model**' )
1173+ table.insert (lines , ' ```' )
1174+ table.insert (lines , selected_model )
1175+ table.insert (lines , ' ```' )
1176+ table.insert (lines , ' ' )
1177+ end
1178+
1179+ if selected_agent then
1180+ table.insert (lines , ' **Agent**' )
1181+ table.insert (lines , ' ```' )
1182+ table.insert (lines , selected_agent )
1183+ table.insert (lines , ' ```' )
1184+ table.insert (lines , ' ' )
1185+ end
1186+
1187+ if system_prompt then
1188+ table.insert (lines , ' **System Prompt**' )
1189+ table.insert (lines , ' ```' )
1190+ for _ , line in ipairs (vim .split (vim .trim (system_prompt ), ' \n ' )) do
1191+ table.insert (lines , line )
1192+ end
1193+ table.insert (lines , ' ```' )
1194+ table.insert (lines , ' ' )
1195+ end
1196+
1197+ async .util .scheduler ()
1198+ state .overlay :show (
1199+ vim .trim (table.concat (lines , ' \n ' )) .. ' \n ' ,
1200+ state .chat .winnr ,
1201+ ' markdown'
1202+ )
1203+ end )
11511204 end )
11521205
1153- map_key (' show_user_selection ' , bufnr , function ()
1154- local selection = get_selection ( state .chat . config )
1155- if not selection then
1206+ map_key (' show_context ' , bufnr , function ()
1207+ local section = state .chat : get_closest_section ( )
1208+ if not section or section . answer then
11561209 return
11571210 end
11581211
1159- state .overlay :show (selection .content , state .chat .winnr , selection .filetype )
1160- end )
1212+ local lines = {}
11611213
1162- map_key (' show_user_context' , bufnr , function ()
1163- local section = state .chat :get_closest_section ()
1214+ local selection = get_selection (state .chat .config )
1215+ if selection then
1216+ table.insert (lines , ' **Selection**' )
1217+ table.insert (lines , ' ```' .. selection .filetype )
1218+ for _ , line in ipairs (vim .split (selection .content , ' \n ' )) do
1219+ table.insert (lines , line )
1220+ end
1221+ table.insert (lines , ' ```' )
1222+ table.insert (lines , ' ' )
1223+ end
11641224
11651225 async .run (function ()
11661226 local embeddings = {}
11671227 if section and not section .answer then
11681228 embeddings = resolve_embeddings (section .content , state .chat .config )
11691229 end
11701230
1171- local text = ' '
11721231 for _ , embedding in ipairs (embeddings ) do
1173- local lines = vim .split (embedding .content , ' \n ' )
1174- local preview = table.concat ( vim .list_slice (lines , 1 , math.min (10 , # lines )), ' \n ' )
1175- local header = string.format (' **`%s` ** (%s lines)' , embedding .filename , # lines )
1176- if # lines > 10 then
1232+ local embed_lines = vim .split (embedding .content , ' \n ' )
1233+ local preview = vim .list_slice (embed_lines , 1 , math.min (10 , # embed_lines ) )
1234+ local header = string.format (' **%s ** (%s lines)' , embedding .filename , # embed_lines )
1235+ if # embed_lines > 10 then
11771236 header = header .. ' (truncated)'
11781237 end
11791238
1180- text = text
1181- .. string.format (' %s\n ```%s\n %s\n ```\n\n ' , header , embedding .filetype , preview )
1239+ table.insert (lines , header )
1240+ table.insert (lines , ' ```' .. embedding .filetype )
1241+ for _ , line in ipairs (preview ) do
1242+ table.insert (lines , line )
1243+ end
1244+ table.insert (lines , ' ```' )
1245+ table.insert (lines , ' ' )
11821246 end
11831247
11841248 async .util .scheduler ()
1185- state .overlay :show (vim .trim (text ) .. ' \n ' , state .chat .winnr , ' markdown' )
1249+ state .overlay :show (
1250+ vim .trim (table.concat (lines , ' \n ' )) .. ' \n ' ,
1251+ state .chat .winnr ,
1252+ ' markdown'
1253+ )
11861254 end )
11871255 end )
11881256
0 commit comments