refactor(picker): canonicalize backend names into single table

Problem: picker backend names were hard-coded as string literals in
`picker/init.lua`, `health.lua`, and `init.lua` validation, making
them easy to get out of sync.

Solution: export `backends` and `detect_order` from `forge.picker` and
reference them in health check and config validation instead of
duplicating the name strings.
This commit is contained in:
Barrett Ruth 2026-03-28 17:50:11 -04:00
parent 97698c2af1
commit ac8db6851f
No known key found for this signature in database
GPG key ID: A6C96C9349D2FC81
3 changed files with 13 additions and 17 deletions

View file

@ -17,13 +17,14 @@ local M = {}
---@field actions forge.PickerActionDef[]
---@field picker_name string
---@type table<string, string>
local backends = {
M.backends = {
['fzf-lua'] = 'forge.picker.fzf',
telescope = 'forge.picker.telescope',
snacks = 'forge.picker.snacks',
}
M.detect_order = { 'fzf-lua', 'snacks', 'telescope' }
---@return string
local function detect()
local cfg = require('forge').config()
@ -31,16 +32,12 @@ local function detect()
if name ~= 'auto' then
return name
end
if pcall(require, 'fzf-lua') then
return 'fzf-lua'
for _, backend in ipairs(M.detect_order) do
if pcall(require, backend) then
return backend
end
end
if pcall(require, 'snacks') then
return 'snacks'
end
if pcall(require, 'telescope') then
return 'telescope'
end
return 'fzf-lua'
return M.detect_order[1]
end
---@param entry forge.PickerEntry
@ -64,7 +61,7 @@ end
---@param opts forge.PickerOpts
function M.pick(opts)
local name = detect()
local mod_path = backends[name]
local mod_path = M.backends[name]
if not mod_path then
vim.notify('[forge]: unknown picker backend: ' .. name, vim.log.levels.ERROR)
return