2021-08-13 22:32:56 +02:00
|
|
|
local M = {}
|
|
|
|
|
2021-10-10 21:07:41 +02:00
|
|
|
local tbl = require "lvim.utils.table"
|
2021-10-09 13:45:34 +02:00
|
|
|
|
2021-08-13 22:32:56 +02:00
|
|
|
function M.is_client_active(name)
|
|
|
|
local clients = vim.lsp.get_active_clients()
|
2021-10-09 13:45:34 +02:00
|
|
|
return tbl.find_first(clients, function(client)
|
|
|
|
return client.name == name
|
|
|
|
end)
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
|
|
|
|
2021-10-09 13:45:34 +02:00
|
|
|
function M.get_active_clients_by_ft(filetype)
|
2021-10-03 16:13:46 +02:00
|
|
|
local matches = {}
|
2021-08-13 22:32:56 +02:00
|
|
|
local clients = vim.lsp.get_active_clients()
|
|
|
|
for _, client in pairs(clients) do
|
2021-10-03 16:13:46 +02:00
|
|
|
local supported_filetypes = client.config.filetypes or {}
|
|
|
|
if client.name ~= "null-ls" and vim.tbl_contains(supported_filetypes, filetype) then
|
|
|
|
table.insert(matches, client)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return matches
|
|
|
|
end
|
|
|
|
|
2021-10-09 13:45:34 +02:00
|
|
|
function M.get_client_capabilities(client_id)
|
2021-12-09 17:08:53 +01:00
|
|
|
local client
|
2021-10-03 16:13:46 +02:00
|
|
|
if not client_id then
|
|
|
|
local buf_clients = vim.lsp.buf_get_clients()
|
2021-12-09 17:08:53 +01:00
|
|
|
for _, buf_client in pairs(buf_clients) do
|
2021-10-03 16:13:46 +02:00
|
|
|
if buf_client.name ~= "null-ls" then
|
2021-12-09 17:08:53 +01:00
|
|
|
client = buf_client
|
2021-10-03 16:13:46 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2021-12-12 19:43:35 +01:00
|
|
|
else
|
|
|
|
client = vim.lsp.get_client_by_id(tonumber(client_id))
|
2021-10-03 16:13:46 +02:00
|
|
|
end
|
2021-12-12 19:43:35 +01:00
|
|
|
if not client then
|
2021-10-03 16:13:46 +02:00
|
|
|
error "Unable to determine client_id"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local enabled_caps = {}
|
|
|
|
for capability, status in pairs(client.resolved_capabilities) do
|
|
|
|
if status == true then
|
|
|
|
table.insert(enabled_caps, capability)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return enabled_caps
|
|
|
|
end
|
|
|
|
|
2021-12-20 08:59:47 +01:00
|
|
|
---Get supported filetypes per server
|
|
|
|
---@param server_name string can be any server supported by nvim-lsp-installer
|
|
|
|
---@return table supported filestypes as a list of strings
|
2021-10-03 16:13:46 +02:00
|
|
|
function M.get_supported_filetypes(server_name)
|
2021-12-20 08:59:47 +01:00
|
|
|
local status_ok, lsp_installer_servers = pcall(require, "nvim-lsp-installer.servers")
|
|
|
|
if not status_ok then
|
|
|
|
return {}
|
2021-10-31 16:23:44 +01:00
|
|
|
end
|
2021-12-20 08:59:47 +01:00
|
|
|
|
2021-10-31 16:23:44 +01:00
|
|
|
local server_available, requested_server = lsp_installer_servers.get_server(server_name)
|
|
|
|
if not server_available then
|
|
|
|
return {}
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
2021-10-31 16:23:44 +01:00
|
|
|
|
|
|
|
return requested_server:get_supported_filetypes()
|
2021-08-13 22:32:56 +02:00
|
|
|
end
|
|
|
|
|
2021-12-20 08:59:47 +01:00
|
|
|
---Get all supported filetypes by nvim-lsp-installer
|
|
|
|
---@return table supported filestypes as a list of strings
|
|
|
|
function M.get_all_supported_filetypes()
|
|
|
|
local status_ok, lsp_installer_filetypes = pcall(require, "nvim-lsp-installer._generated.filetype_map")
|
|
|
|
if not status_ok then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
return vim.tbl_keys(lsp_installer_filetypes or {})
|
|
|
|
end
|
|
|
|
|
2021-08-13 22:32:56 +02:00
|
|
|
return M
|