From 6c3cbbc4d5300a6e934e881606436748cc3e72dd Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 23 Aug 2022 13:20:29 +0200 Subject: fix: only consider servers that have been set up as available (#2066) * test: add failing test * fix(lspconfig): only consider servers that have been set up as available --- lua/lspconfig.lua | 8 +++++++- test/lspconfig_spec.lua | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lua/lspconfig.lua b/lua/lspconfig.lua index 779ec426..b46ef65d 100644 --- a/lua/lspconfig.lua +++ b/lua/lspconfig.lua @@ -7,7 +7,13 @@ local M = { M._root = {} function M.available_servers() - return vim.tbl_keys(configs) + local servers = {} + for server, config in pairs(configs) do + if config.manager ~= nil then + table.insert(servers, server) + end + end + return servers end -- Called from plugin/lspconfig.vim because it requires knowing that the last diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 163bf887..8fc117c5 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -251,5 +251,19 @@ describe('lspconfig', function() } ) end) + + it("excludes indexed server configs that haven't been set up", function() + eq( + exec_lua [[ + local lspconfig = require("lspconfig") + local actual = nil + local _ = lspconfig.sumneko_lua + local _ = lspconfig.tsserver + lspconfig.rust_analyzer.setup {} + return lspconfig.available_servers() + ]], + { 'rust_analyzer' } + ) + end) end) end) -- cgit v1.2.3-70-g09d2