mirror of
https://github.com/neovim/neovim.git
synced 2026-05-02 20:15:03 +00:00
feat(lsp): vim.lsp.get_configs() #37237
Problem: No way to iterate configs. Users need to reach for `vim.lsp.config._configs`, an internal interface. Solution: Provide vim.lsp.get_configs(). Also indirectly improves :lsp enable/disable completion by discarding invalid configs from completion.
This commit is contained in:
@@ -19,45 +19,22 @@ local function get_client_names()
|
||||
:totable()
|
||||
end
|
||||
|
||||
--- @return string[]
|
||||
local function get_config_names()
|
||||
local config_names = vim
|
||||
.iter(api.nvim_get_runtime_file('lsp/*.lua', true))
|
||||
--- @param path string
|
||||
:map(function(path)
|
||||
local file_name = path:match('[^/]*.lua$')
|
||||
return file_name:sub(0, #file_name - 4)
|
||||
end)
|
||||
:totable()
|
||||
|
||||
--- @diagnostic disable-next-line
|
||||
vim.list_extend(config_names, vim.tbl_keys(lsp.config._configs))
|
||||
|
||||
return vim
|
||||
.iter(config_names)
|
||||
:unique()
|
||||
--- @param name string
|
||||
:filter(function(name)
|
||||
return name ~= '*'
|
||||
end)
|
||||
:totable()
|
||||
end
|
||||
|
||||
--- @param filter fun(string):boolean
|
||||
--- @param filter vim.lsp.get_configs.Filter
|
||||
--- @return fun():string[]
|
||||
local function filtered_config_names(filter)
|
||||
return function()
|
||||
return vim.iter(get_config_names()):filter(filter):totable()
|
||||
return vim
|
||||
.iter(lsp.get_configs(filter))
|
||||
:map(function(config)
|
||||
return config.name
|
||||
end)
|
||||
:totable()
|
||||
end
|
||||
end
|
||||
|
||||
local complete_args = {
|
||||
enable = filtered_config_names(function(name)
|
||||
return not lsp.is_enabled(name)
|
||||
end),
|
||||
disable = filtered_config_names(function(name)
|
||||
return lsp.is_enabled(name)
|
||||
end),
|
||||
enable = filtered_config_names { enabled = false },
|
||||
disable = filtered_config_names { enabled = true },
|
||||
restart = get_client_names,
|
||||
stop = get_client_names,
|
||||
}
|
||||
@@ -79,17 +56,10 @@ local function ex_lsp_enable(config_names)
|
||||
-- Default to enabling all clients matching the filetype of the current buffer.
|
||||
if #config_names == 0 then
|
||||
local filetype = vim.bo.filetype
|
||||
for _, name in ipairs(get_config_names()) do
|
||||
local success, result = pcall(function()
|
||||
return lsp.config[name]
|
||||
end)
|
||||
if success then
|
||||
local filetypes = result.filetypes
|
||||
if filetypes == nil or vim.list_contains(filetypes, filetype) then
|
||||
table.insert(config_names, name)
|
||||
end
|
||||
else
|
||||
echo_err(result --[[@as string]])
|
||||
for _, config in ipairs(lsp.get_configs()) do
|
||||
local filetypes = config.filetypes
|
||||
if filetypes == nil or vim.list_contains(filetypes, filetype) then
|
||||
table.insert(config_names, config.name)
|
||||
end
|
||||
end
|
||||
if #config_names == 0 then
|
||||
|
||||
Reference in New Issue
Block a user