Generic list_or_jump
items filtering mechanism
#3401
Labels
enhancement
Enhancement to performance, inner workings or existent features
Is your feature request related to a problem? Please describe.
Sometimes I work on a React codebase, where I frequently use
require('telescope.builtin').lsp_definitions
to go to a component's definition. Currently,lsp_definitions
opens a picker with two options:I rarely need the second option and would like to see it only if there are no other options available (e.g., "native" elements like
div
orform
). So I need to filter out certain patterns only if more than one result is available.Describe the solution you'd like
The
lsp_definitions
function callslist_or_jump
inside:telescope.nvim/lua/telescope/builtin/__lsp.lua
Lines 293 to 296 in 415af52
The
list_or_jump
function already has some form of filtering (ignoring files if they match user-given patterns):telescope.nvim/lua/telescope/builtin/__lsp.lua
Line 236 in 415af52
telescope.nvim/lua/telescope/builtin/__lsp.lua
Lines 175 to 190 in 415af52
While it helps with static patterns (meaning patterns that don't depend on any other conditions), it doesn't allow for arbitrary conditions while filtering.
I suggest adding a callback called
filter_items
that enables users to filter thevim.quickfix.entry[]
list (calleditems
in thelist_or_jump
implementation) to make it flexible for users who want to control what is presented in the picker.Judging by how many "public" functions use
list_or_jump
internally, addingfilter_items
would extend all these "public" functions in a helpful way without making a lot of changes.Describe alternatives you've considered
Any other form of "hooking" into Telescope's internals that decide what the picker will show.
Additional context
Possible implementation:
For each function in
builtin/init.lua
that useslist_or_jump
internally, add a new field---@field filter_items FilterItemsCallback: callback to filter out quickfix entries that should be ignored
The type itself:
Add a default implementation of
filter_items
in case a user didn't provide one:Call
opts.filter_items
after other filtering:How to use:
I can create a PR quickly (I already have a working version locally).
The text was updated successfully, but these errors were encountered: