-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Description
Problem
vim.ui.select is designed to not care about the structure of the item, but that leads to plugins that enhance it being unable to properly infer how to do previewing, which happens to be the great value that all the picker plugins are adding, and lead to plugins authors directly go calling the specific plugin's API when they want to give users a list to choose from, instead of vim.ui.select interface, which become maintenance burden.
The only effort so far is the kind field introduced here: #15838
But going through the popular fuzzy finder's custom ui select handler, I think only fzf-lua treated this field with extra care if kind is codeaction. So an arbitrary string is simply not enough, and trying to make this a enum will fall into the trap of caring too much about the structure of the item and not being a generic interface.
Expected behavior
Add a preview field with signature fun(item, item_idx): buf
so a minimal buffer picker will look like:
vim.ui.select(vim.api.nvim_list_bufs(), {
preview = function(buf)
return buf
end,
format_item = function(buf)
return vim.api.nvim_buf_get_name(buf)
end,
}, function(buf)
vim.cmd.buffer(buf)
end)The advantage of this approach is that it vim.ui.select still don't need to know that it is rendering or the structure of the item, the caller decides whether they want to render a diff, a help file, a normal buffer, or a term buffer.
I have tried adding support for this kind of simple preview field for the mainstream pickers, and they work pretty well, and are just minor changes, so I believe we can add this "contract", so that plugin authors will call vim.ui.select for 80% of the time, and not care about what handler the users are using.
I can draft a PR if this makes sense.
p.s. Here's where I got the idea: #35943 (reply in thread)
But I have not found the discussions mentioned on how this relates to bringing vim.ui closer to LSP capabilities
p.s. preview_item might be a better name, to be more consistent with format_item, and it seems to be what mini.pick is using internally.