telescope-zf-native.nvim icon indicating copy to clipboard operation
telescope-zf-native.nvim copied to clipboard

`initial_sort` should not be applied to `oldfiles`

Open chrisgrieser opened this issue 1 year ago • 5 comments

I noticed that the initial_sort for files also affects the oldfiles picker. This is somewhat unfortunate, since oldfiles is the one picker where the initial order of files actually makes sense as they are sorted by recency.

Applying the initial sort here basically makes the oldfiles picker worse. Could the oldfiles picker therefore be excluded from initial_sort?

chrisgrieser avatar Feb 04 '24 13:02 chrisgrieser

Hmmm, that is unfortunate.

I'm not sure if a sorter can know what picker is being used. I'll take a look though.

Instead of making zf aware of the picker, is is possible to configure the oldfiles picker to use different configuration?

natecraddock avatar Feb 04 '24 15:02 natecraddock

I don't know. I tried setting file_sorter to the basic one from telescope, but it looks like it does not have any effect.

chrisgrieser avatar Feb 04 '24 16:02 chrisgrieser

Okay, I think I figured it out. The code for the oldfiles picker (https://github.com/nvim-telescope/telescope.nvim/blob/7b5c5f56a21e82fdcfe5b250278b8dfc4b1cbab4/lua/telescope/builtin/__internal.lua#L523-L524) uses sorter = conf.file_sorter(opts), to set the sorter.

I dug through the code a bit more, and found how to access that opts table passed to the sorter.

Here's a branch with the code: https://github.com/natecraddock/telescope-zf-native.nvim/tree/picker-opts

And how I tested:

:lua require('telescope.builtin').oldfiles({skip_initial_sort = true})`
    ['zf-native'] = {
      file = {
         initial_sort = function (line, picker_opts)
           if picker_opts.skip_initial_sort then return 0 end

           if line:match('.c$') then
             return 0
           end
           return 1
         end
      }
    }

natecraddock avatar Feb 04 '24 17:02 natecraddock

thx! While that works, I wonder, whether one could simply use the approach suggested in the telescope repo and just set the sorter for find_files to simplify things 🤔

chrisgrieser avatar Feb 04 '24 18:02 chrisgrieser

Hmmm. I'm not sure I follow. It looks like the suggestion in telescope involves wrapping the sorter? How does that apply to oldfiles?

Wait maybe I understand better. Are you suggesting that zf only register itself as a sorter for find_files?

natecraddock avatar Feb 05 '24 22:02 natecraddock

Hey @chrisgrieser! Just checking in. Is this something you are still wanting me to look into? If not I'll close this issue

natecraddock avatar Jun 12 '24 03:06 natecraddock

hey! Sorry for not getting back. Yeah, I think the approach suggested at https://github.com/nvim-telescope/telescope.nvim/issues/2905#issuecomment-1922729686 is preferable, since it works for Telescope in general, instead of just a specific Telescope extension.

(Though I every much would prefer to simply have a Telescope setting for it, as I initially suggested in the issue, but that's a different question I guess)

chrisgrieser avatar Jun 12 '24 05:06 chrisgrieser