fix(picker): lsp_config now includes any configfured LSP and excludes deprecated servers

This commit is contained in:
Folke Lemaitre 2025-09-16 11:57:15 +02:00
parent f2746da0bb
commit a0d6eba1a2
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -12,6 +12,7 @@ local has_11 = vim.fn.has("nvim-0.11") == 1
---@field attached_buf? boolean
---@field enabled? boolean
---@field installed? boolean
---@field deprecated? boolean
---@field cmd? string[]
---@field bin? string
@ -19,6 +20,7 @@ local has_11 = vim.fn.has("nvim-0.11") == 1
---@field config vim.lsp.Config
---@field enabled? boolean
---@field docs? string
---@field deprecated? boolean
---@param name string
local function is_enabled(name)
@ -33,9 +35,14 @@ end
local function get_config(name)
local modpath = vim.api.nvim_get_runtime_file("lsp/" .. name .. ".lua", false)[1]
local ret = { config = {} } ---@type snacks.picker.lsp.config.Config
local deprecate = vim.deprecate
vim.deprecate = function()
ret.deprecated = true
end
local ok, config = pcall(function()
return has_11 and vim.lsp.config[name] or loadfile(modpath)() or {}
end)
vim.deprecate = deprecate
ret.config = ok and config or {}
ret.enabled = is_enabled(name)
local lines = modpath and Snacks.picker.util.lines(modpath) or {}
@ -57,15 +64,19 @@ end
---@type snacks.picker.finder
function M.find(opts, ctx)
local all = vim.api.nvim_get_runtime_file("lsp/*.lua", true)
local available = {} ---@type string[]
local available = {} ---@type table<string, string>
for _, f in ipairs(all) do
local name = f:match("([^/\\]+)%.lua$")
if name then
available[#available + 1] = name
available[name] = name
end
end
if #all == 0 then
for name in pairs(has_11 and vim.lsp.config._configs or {}) do
available[name] = name
end
if vim.tbl_count(available) == 0 then
Snacks.notify.warn("No LSP configurations found?")
return {}
end
@ -78,6 +89,7 @@ function M.find(opts, ctx)
item.config = item.config or mod.config
item.cmd = item.cmd or mod.config.cmd
item.enabled = item.enabled or mod.enabled
item.deprecated = mod.deprecated
end
local items = {} ---@type table<string, snacks.picker.lsp.config.Item>
@ -97,7 +109,7 @@ function M.find(opts, ctx)
items[client.name].attached_buf = items[client.name].buffers[main_buf]
end
for _, name in ipairs(available) do
for name in pairs(available) do
items[name] = items[name] or {
name = name,
buffers = {},
@ -136,6 +148,7 @@ function M.find(opts, ctx)
want = false
end
end
want = want and not item.deprecated
if want then
cb({
name = name,