From be92be6124f743c30ba4b52ded908d02cfb80a1b Mon Sep 17 00:00:00 2001 From: Rohith Ravi Date: Tue, 24 Dec 2024 06:48:37 -0800 Subject: [PATCH] feat(context): mention @quickfix to add files in qf to context (#988) Neovim allows quickfix list to be populated in a variety of ways: grep, lsp symbol references etc. Being able to add files in the quickfix window to the LLM chat context allows for interesting workflows. For example, one could search for a symbol using the LSP integration, populate the quickfix with that list and then pass those along as context in Avante using @quickfix mention in the sidebar. If there are no files in the quickfix list or the items do not have a file, nothing is added to the context. --- lua/avante/file_selector.lua | 12 ++++++++++++ lua/avante/sidebar.lua | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 58c20a1da..5e289bfa8 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -267,4 +267,16 @@ end function FileSelector:get_selected_filepaths() return vim.deepcopy(self.selected_filepaths) end +---@return nil +function FileSelector:add_quickfix_files() + local quickfix_files = vim + .iter(vim.fn.getqflist({ items = 0 }).items) + :filter(function(item) return item.bufnr ~= 0 end) + :map(function(item) return Utils.relative_path(vim.api.nvim_buf_get_name(item.bufnr)) end) + :totable() + for _, filepath in ipairs(quickfix_files) do + self:add_selected_file(filepath) + end +end + return FileSelector diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index fe5321c0e..4e6a06ee2 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1803,6 +1803,13 @@ function Sidebar:create_input_container(opts) callback = function() self.file_selector:open() end, }) + table.insert(mentions, { + description = "quickfix", + command = "quickfix", + details = "add files in quickfix list to chat context", + callback = function() self.file_selector:add_quickfix_files() end, + }) + cmp.register_source( "avante_commands", require("cmp_avante.commands"):new(self:get_commands(), self.input_container.bufnr)