feat: added lsp user commands to clear logs and print available language servers...
[edyt.git] / lua / lsp / fn / list_available_ls.lua
blobdd4a31ea13a0ab2cfe33cc799977f590545e290b
1 local asked = {}
3 --- @param t table|nil list language servers available from Mason for current filetype
4 local list_available_ls = function(t)
5 if not t then
6 t = {
7 buf = 0,
8 match = vim.fn.input({ prompt = "Filetype: ", default = vim.bo.filetype }),
9 all = true
11 end
12 if not vim.bo[t.buf].buftype == "" then return end
14 if not t.all and asked[t.match] then return end
15 asked[t.match] = true
17 if not t.all and vim.tbl_contains(require("lsp.fn.mason_exclude"), t.match) then return end
19 local mason_config = require("mason-lspconfig")
20 local available_servers = mason_config.get_available_servers({ filetype = t.match })
22 if #available_servers == 0 then return end
24 local installed_servers = mason_config.get_installed_servers()
25 for a, available in ipairs(available_servers) do
26 if vim.tbl_contains(require("lsp.fn.mason_exclude"), available) then return end
27 for _, installed in ipairs(installed_servers) do
28 if available == installed then
29 available_servers[a] = installed .. " " .. "✓"
30 if not t.all then return end
31 end
32 end
33 end
34 vim.ui.select(available_servers,
35 { prompt = "Select lsp server to install: " },
36 function(item)
37 if item then vim.cmd("LspInstall " .. item) end
38 end)
39 end
41 vim.api.nvim_create_user_command("LspAvailable", function() list_available_ls() end, {})
43 return list_available_ls