refactor: remove fzf_lua implementation; defer directly to fzf_lua

Since fzf-lua ships with an implementation for vim.ui.select, we should
use that directly instead of creating our own wrapper. It reduces
overall code duplication and reduces the surface area for bugs to creep
in.
This commit is contained in:
Steven Arcangeli 2023-04-12 05:43:56 -07:00
parent 0c999b7b96
commit a89327e245
3 changed files with 8 additions and 39 deletions

View File

@ -88,14 +88,6 @@ local default_config = {
},
},
-- Options for fzf_lua selector
fzf_lua = {
winopts = {
width = 0.5,
height = 0.4,
},
},
-- Options for nui Menu
nui = {
position = "50%",

View File

@ -1,40 +1,17 @@
local M = {}
M.is_supported = function()
return pcall(require, "fzf-lua")
return pcall(require, "fzf-lua.providers.ui_select")
end
M.select = function(config, items, opts, on_choice)
local fzf = require("fzf-lua")
local labels = {}
for i, item in ipairs(items) do
table.insert(labels, string.format("%d: %s", i, opts.format_item(item)))
if config then
vim.notify_once(
"Deprecated: dressing config for fzf_lua has been removed in favor of using the built-in fzf-lua vim.ui.select implementation.\nRemove the fzf_lua key from dressing.setup()",
vim.log.levels.WARN
)
end
local prompt = (opts.prompt or "Select one of") .. "> "
local fzf_opts = vim.tbl_deep_extend("keep", config, {
prompt = prompt,
fzf_opts = {
["--no-multi"] = "",
["--preview-window"] = "hidden:right:0",
},
actions = {
-- "default" gets called when pressing "enter"
-- all fzf style binds (i.e. "ctrl-y") are valid
["default"] = function(selected, _)
if not selected then
on_choice(nil, nil)
else
local label = selected[1]
local lnum = tonumber(label:match("^(%d+):"))
local item = items[lnum]
on_choice(item, lnum)
end
end,
},
})
fzf.fzf_exec(labels, fzf_opts)
return require("fzf-lua.providers.ui_select").ui_select(items, opts, on_choice)
end
return M

View File

@ -5,7 +5,7 @@ local function run_test(backend)
local prev_backend = config.select.backend
config.select.backend = backend
vim.ui.select({ "first", "second", "third" }, {
prompt = "Make selection",
prompt = "Make selection: ",
kind = "test",
}, function(item, lnum)
if item and lnum then