Skip to content

Commit d853257

Browse files
committed
feat: add quickfix list context support
This commit adds support for the quickfix list context in CopilotChat. The quickfix context allows including the contents of files listed in the quickfix list as part of the chat context. The implementation includes: - New quickfix context type in config.lua - Function to extract and process quickfix list files - Updated documentation in README.md with the new context type Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 1b375c2 commit d853257

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Default contexts are:
262262
- `git:staged` - Includes staged changes in chat context.
263263
- `url` - Includes content of provided URL in chat context. Supports input.
264264
- `register` - Includes contents of register in chat context. Supports input (default +, e.g clipboard).
265+
- `quickfix` - Includes quickfix list file contents in chat context.
265266

266267
You can define custom contexts like this:
267268

@@ -487,6 +488,9 @@ Also see [here](/lua/CopilotChat/config.lua):
487488
register = {
488489
-- see config.lua for implementation
489490
},
491+
quickfix = {
492+
-- see config.lua for implementation
493+
},
490494
},
491495

492496
-- default prompts

lua/CopilotChat/config.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ return {
283283
}
284284
end,
285285
},
286+
quickfix = {
287+
description = 'Includes quickfix list file contents in chat context.',
288+
resolve = function()
289+
return context.quickfix()
290+
end,
291+
},
286292
},
287293

288294
-- default prompts

lua/CopilotChat/context.lua

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ end
282282
---@param filetype string
283283
---@return CopilotChat.context.embed?
284284
local function get_file(filename, filetype)
285+
notify.publish(notify.STATUS, 'Reading file ' .. filename)
286+
285287
local modified = utils.file_mtime(filename)
286288
if not modified then
287289
return nil
@@ -377,8 +379,6 @@ function M.file(filename)
377379
return nil
378380
end
379381

380-
notify.publish(notify.STATUS, 'Reading file ' .. filename)
381-
382382
async.util.scheduler()
383383
local ft = utils.filetype(filename)
384384
if not ft then
@@ -532,6 +532,46 @@ function M.register(register)
532532
}
533533
end
534534

535+
--- Get the content of the quickfix list
536+
---@return table<CopilotChat.context.embed>
537+
function M.quickfix()
538+
async.util.scheduler()
539+
540+
local items = vim.fn.getqflist()
541+
if not items or #items == 0 then
542+
return {}
543+
end
544+
545+
local unique_files = {}
546+
for _, item in ipairs(items) do
547+
local filename = item.filename or vim.api.nvim_buf_get_name(item.bufnr)
548+
if filename then
549+
unique_files[filename] = true
550+
end
551+
end
552+
553+
local files = vim.tbl_filter(
554+
function(file)
555+
return file.ft ~= nil
556+
end,
557+
vim.tbl_map(function(file)
558+
return {
559+
name = utils.filepath(file),
560+
ft = utils.filetype(file),
561+
}
562+
end, vim.tbl_values(unique_files))
563+
)
564+
565+
local out = {}
566+
for _, file in ipairs(files) do
567+
local file_data = get_file(file.name, file.ft)
568+
if file_data then
569+
table.insert(out, file_data)
570+
end
571+
end
572+
return out
573+
end
574+
535575
--- Filter embeddings based on the query
536576
---@param copilot CopilotChat.Copilot
537577
---@param prompt string

0 commit comments

Comments
 (0)