Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: quickfixhistory should choose existing history #3273

Open
ColinKennedy opened this issue Sep 2, 2024 · 5 comments
Open

Request: quickfixhistory should choose existing history #3273

ColinKennedy opened this issue Sep 2, 2024 · 5 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@ColinKennedy
Copy link

Is your feature request related to a problem? Please describe.
If I call :chistory, it lists 2 entries

   error list 1 of 2; 1392 errors  rg --vimgrep something ./
> error list 2 of 2; 640 errors   rg --vimgrep bundle ./

If I call :Telescope quickfixhistory and select an entry and press Ctrl-q, it creates a new quickfix entry

   error list 1 of 3; 1392 errors  rg --vimgrep something ./
   error list 2 of 3; 640 errors   rg --vimgrep bundle ./
> error list 3 of 3; 1392 errors  Quickfix ()

Telescope Ctrl-q is normally meant to convert the current Telescope entries into a quickfix but for quickfixhistory it'd make more sense for to reuse the quickfix entry instead assuming the user hasn't selected any custom entries to filter by. Or maybe as a different mapping. So even if you select a quickfix list, Vim doesn't create a new one.

The quickfix list is a limited resource. You only get 10 entries. So the plugin creating a new entry each time you call :Telescope quickfixhistory is pretty inconvenient.

Describe the solution you'd like
ctrl-q selects the quickfix history instead of creating a new quickfix history entry wherever possible.

Describe alternatives you've considered
Maybe instead keep ctrl-q the same but provide a new mapping which does select the quickfix entry.

@ColinKennedy ColinKennedy added the enhancement Enhancement to performance, inner workings or existent features label Sep 2, 2024
@ColinKennedy ColinKennedy changed the title quickfixhistory should choose existing history Request: quickfixhistory should choose existing history Sep 2, 2024
@jamestrew
Copy link
Contributor

Do you have an proposal on how to achieve this? I'm far from a quickfix list guru.

Seems to me like after selecting a quickfix list as an entry in :Telescope quickfixhistory, in order to accurately reopen the previously selected qflist with <C-q>, we'd need to do some comparison of the lists since one could filter the results and alter what to send to qflist. Seems like a hassle...

@ColinKennedy
Copy link
Author

ColinKennedy commented Sep 18, 2024

The easiest way is to just provide a separate keymap that selects a quickfix history directly based on the first display's selected row. Then no custom ctrl-q is needed.

That said I think a custom ctrl-q could be less effort than you're imagining. As long as Telescope can report the selected row, that can be used as a quickfix index. Then basically the code becomes (roughly)

local index = _get_the_selected_quickfix_index_row_from_telescope()
local selected_entries = _get_the_selected_entries_telescope()

if not selected_entries or vim.tbl_isempty(selected_entries) then
    _select_the_quickfix_by_index(index)

    return
end

local all_entries = vim.fn.getqflist({id=index, all=0})
local filtered_entries = vim.iter(all_entries.items):map(
    function(value) return _remove_any_excess_if_needed(value) end
):totable()

if not vim.deep_equal(selected_entries, filtered_entries) then
    -- Basically the current logic that nvim-telescope is doing goes here
    _create_new_quickfix_with_selected_entries(selected_entries)
else
    -- NOTE: This is rare but if they select every entry, just select the quickfix index
    _select_the_quickfix_by_index(index)
end

I haven't looked at the Telescope implementation so this code is a bit pseudo but something along these lines seems reasonable. What do you think?

@jamestrew
Copy link
Contributor

That might still require some rework of the existing picker implementation.
If you'd like to try implementing this, I could support that.

@ColinKennedy
Copy link
Author

ColinKennedy commented Sep 27, 2024

Silly me, turns out it actually already has that feature -

map({ "i", "n" }, "<C-q>", function(prompt_bufnr)
local nr = action_state.get_selected_entry().nr
actions.close(prompt_bufnr)
vim.cmd(nr .. "chistory")
vim.cmd "botright copen"
end)

It would be nice if there's a command to "go back" in case I dive into a quickfixhistory and see that I actually want the whole of a quickfix but this is enough. Because sometimes you don't know you want an qf until you see its entries

But if you don't dive into the second picker and <C-q>, it already does select the history.

@crazyminecuber
Copy link

A somewhat related question. Do you also think the sorting of the quickfix list history picker is wrong? For me, the first selected quickfix history item is the oldest quickfix history item. I think it would make much more sense to reverse the sorting order so that the youngest quickfix history item, is the first selected item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

3 participants