summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorfdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>2022-05-04 21:50:15 +0200
committerGitHub <noreply@github.com>2022-05-04 21:50:15 +0200
commit8d1841bff5c70d05f458ded09e465ae4ac21ecce (patch)
treee40f3d3c0fc471daee425d906b469cdebba8f2fd /lua/telescope
parentc93276acd34f5cb20d7cc2de15a8f40526433660 (diff)
feat: quickfixhistory picker (#1878)
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/actions/init.lua6
-rw-r--r--lua/telescope/builtin/init.lua6
-rw-r--r--lua/telescope/builtin/internal.lua62
3 files changed, 73 insertions, 1 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index 5899629..11b46a2 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -794,12 +794,15 @@ local send_selected_to_qf = function(prompt_bufnr, mode, target)
table.insert(qf_entries, entry_to_qf(entry))
end
+ local prompt = picker:_get_prompt()
actions.close(prompt_bufnr)
if target == "loclist" then
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
else
+ local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt)
vim.fn.setqflist(qf_entries, mode)
+ vim.fn.setqflist({}, "a", { title = qf_title })
end
end
@@ -812,12 +815,15 @@ local send_all_to_qf = function(prompt_bufnr, mode, target)
table.insert(qf_entries, entry_to_qf(entry))
end
+ local prompt = picker:_get_prompt()
actions.close(prompt_bufnr)
if target == "loclist" then
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
else
vim.fn.setqflist(qf_entries, mode)
+ local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt)
+ vim.fn.setqflist({}, "a", { title = qf_title })
end
end
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index b73c970..e8e88e8 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -241,8 +241,14 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman
---@param opts table: options to pass to the picker
---@field ignore_filename boolean: dont show filenames (default: true)
---@field trim_text boolean: trim results text (default: false)
+---@field nr number: specify the quickfix list number
builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix
+--- Lists all quickfix lists in your history and open them with `builtin.quickfix`. It seems that neovim
+--- only keeps the full history for 10 lists
+---@param opts table: options to pass to the picker
+builtin.quickfixhistory = require_on_exported_call("telescope.builtin.internal").quickfixhistory
+
--- Lists items from the current window's location list, jumps to location on `<cr>`
---@param opts table: options to pass to the picker
---@field ignore_filename boolean: dont show filenames (default: true)
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index 122827f..be244cc 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -359,7 +359,8 @@ internal.commands = function(opts)
end
internal.quickfix = function(opts)
- local locations = vim.fn.getqflist()
+ local qf_identifier = opts.id or vim.F.if_nil(opts.nr, "$")
+ local locations = vim.fn.getqflist({ [opts.id and "id" or "nr"] = qf_identifier, items = true }).items
if vim.tbl_isempty(locations) then
return
@@ -376,6 +377,65 @@ internal.quickfix = function(opts)
}):find()
end
+internal.quickfixhistory = function(opts)
+ local qflists = {}
+ for i = 1, 10 do -- (n)vim keeps at most 10 quickfix lists in full
+ -- qf weirdness: id = 0 gets id of quickfix list nr
+ local qflist = vim.fn.getqflist { nr = i, id = 0, title = true, items = true }
+ if not vim.tbl_isempty(qflist.items) then
+ table.insert(qflists, qflist)
+ end
+ end
+ local entry_maker = opts.make_entry
+ or function(entry)
+ return {
+ value = entry.title or "Untitled",
+ ordinal = entry.title or "Untitled",
+ display = entry.title or "Untitled",
+ nr = entry.nr,
+ id = entry.id,
+ items = entry.items,
+ }
+ end
+ local qf_entry_maker = make_entry.gen_from_quickfix(opts)
+ pickers.new(opts, {
+ prompt_title = "Quickfix History",
+ finder = finders.new_table {
+ results = qflists,
+ entry_maker = entry_maker,
+ },
+ previewer = previewers.new_buffer_previewer {
+ title = "Quickfix List Preview",
+ dyn_title = function(_, entry)
+ return entry.title
+ end,
+
+ get_buffer_by_name = function(_, entry)
+ return "quickfixlist_" .. tostring(entry.nr)
+ end,
+
+ define_preview = function(self, entry)
+ if self.state.bufname then
+ return
+ end
+ local entries = vim.tbl_map(function(i)
+ return qf_entry_maker(i):display()
+ end, entry.items)
+ vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries)
+ end,
+ },
+ sorter = conf.generic_sorter(opts),
+ attach_mappings = function(_, _)
+ action_set.select:replace(function(prompt_bufnr)
+ local nr = action_state.get_selected_entry().nr
+ actions.close(prompt_bufnr)
+ internal.quickfix { nr = nr }
+ end)
+ return true
+ end,
+ }):find()
+end
+
internal.loclist = function(opts)
local locations = vim.fn.getloclist(0)
local filenames = {}