feat: quickfixhistory picker (#1878)
This commit is contained in:
@@ -279,6 +279,7 @@ Built-in functions. Ready to be bound to any key you like.
|
|||||||
| `builtin.marks` | Lists vim marks and their value |
|
| `builtin.marks` | Lists vim marks and their value |
|
||||||
| `builtin.colorscheme` | Lists available colorschemes and applies them on `<cr>` |
|
| `builtin.colorscheme` | Lists available colorschemes and applies them on `<cr>` |
|
||||||
| `builtin.quickfix` | Lists items in the quickfix list |
|
| `builtin.quickfix` | Lists items in the quickfix list |
|
||||||
|
| `builtin.quickfixhistory` | Lists all quickfix lists in your history and open them with `builtin.quickfix` |
|
||||||
| `builtin.loclist` | Lists items from the current window's location list |
|
| `builtin.loclist` | Lists items from the current window's location list |
|
||||||
| `builtin.jumplist` | Lists Jump List entries |
|
| `builtin.jumplist` | Lists Jump List entries |
|
||||||
| `builtin.vim_options` | Lists vim options, allows you to edit the current value on `<cr>` |
|
| `builtin.vim_options` | Lists vim options, allows you to edit the current value on `<cr>` |
|
||||||
|
|||||||
@@ -1117,6 +1117,17 @@ builtin.quickfix({opts}) *telescope.builtin.quickfix()*
|
|||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{ignore_filename} (boolean) dont show filenames (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{nr} (number) specify the quickfix list number
|
||||||
|
|
||||||
|
|
||||||
|
builtin.quickfixhistory({opts}) *telescope.builtin.quickfixhistory()*
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
|
|
||||||
builtin.loclist({opts}) *telescope.builtin.loclist()*
|
builtin.loclist({opts}) *telescope.builtin.loclist()*
|
||||||
|
|||||||
@@ -794,12 +794,15 @@ local send_selected_to_qf = function(prompt_bufnr, mode, target)
|
|||||||
table.insert(qf_entries, entry_to_qf(entry))
|
table.insert(qf_entries, entry_to_qf(entry))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local prompt = picker:_get_prompt()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
if target == "loclist" then
|
if target == "loclist" then
|
||||||
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
|
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
|
||||||
else
|
else
|
||||||
|
local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt)
|
||||||
vim.fn.setqflist(qf_entries, mode)
|
vim.fn.setqflist(qf_entries, mode)
|
||||||
|
vim.fn.setqflist({}, "a", { title = qf_title })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -812,12 +815,15 @@ local send_all_to_qf = function(prompt_bufnr, mode, target)
|
|||||||
table.insert(qf_entries, entry_to_qf(entry))
|
table.insert(qf_entries, entry_to_qf(entry))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local prompt = picker:_get_prompt()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
if target == "loclist" then
|
if target == "loclist" then
|
||||||
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
|
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
|
||||||
else
|
else
|
||||||
vim.fn.setqflist(qf_entries, mode)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -241,8 +241,14 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman
|
|||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field ignore_filename boolean: dont show filenames (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@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
|
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>`
|
--- Lists items from the current window's location list, jumps to location on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field ignore_filename boolean: dont show filenames (default: true)
|
||||||
|
|||||||
@@ -359,7 +359,8 @@ internal.commands = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
internal.quickfix = function(opts)
|
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
|
if vim.tbl_isempty(locations) then
|
||||||
return
|
return
|
||||||
@@ -376,6 +377,65 @@ internal.quickfix = function(opts)
|
|||||||
}):find()
|
}):find()
|
||||||
end
|
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)
|
internal.loclist = function(opts)
|
||||||
local locations = vim.fn.getloclist(0)
|
local locations = vim.fn.getloclist(0)
|
||||||
local filenames = {}
|
local filenames = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user