From d01ba08eaec1640ac2d038893525b3ba0af25813 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:13:46 +0200 Subject: refactor: auto-generate language configuration (#1584) Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files. --- lua/lsp/utils.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'lua/lsp/utils.lua') diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 17b9c3bc..1a5dd79d 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -10,19 +10,60 @@ function M.is_client_active(name) return false end --- FIXME: this should return a list instead -function M.get_active_client_by_ft(filetype) - if not lvim.lang[filetype] or not lvim.lang[filetype].lsp then - return nil - end +function M.disable_formatting_capability(client) + -- FIXME: figure out a reasonable way to do this + client.resolved_capabilities.document_formatting = false + require("core.log"):debug(string.format("Turning off formatting capability for language server [%s] ", client.name)) +end +function M.get_active_client_by_ft(filetype) + local matches = {} local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do - if client.name == lvim.lang[filetype].lsp.provider then - return client + 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 + +function M.get_ls_capabilities(client_id) + if not client_id then + local buf_clients = vim.lsp.buf_get_clients() + for _, buf_client in ipairs(buf_clients) do + if buf_client.name ~= "null-ls" then + client_id = buf_client.id + break + end + end + end + if not client_id then + error "Unable to determine client_id" + return + end + + local client = vim.lsp.get_client_by_id(tonumber(client_id)) + + 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 + +function M.get_supported_filetypes(server_name) + -- print("got filetypes query request for: " .. server_name) + local configs = require "lspconfig/configs" + pcall(require, ("lspconfig/" .. server_name)) + for _, config in pairs(configs) do + if config.name == server_name then + return config.document_config.default_config.filetypes or {} end end - return nil end return M -- cgit v1.2.3 From 195b07a464d37328892a502cf7ce3690b6a5b2e4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:38:35 +0200 Subject: fix(lsp): use correct check for formatter override (#1726) --- lua/lsp/utils.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lua/lsp/utils.lua') diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 1a5dd79d..87ba2337 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -10,12 +10,6 @@ function M.is_client_active(name) return false end -function M.disable_formatting_capability(client) - -- FIXME: figure out a reasonable way to do this - client.resolved_capabilities.document_formatting = false - require("core.log"):debug(string.format("Turning off formatting capability for language server [%s] ", client.name)) -end - function M.get_active_client_by_ft(filetype) local matches = {} local clients = vim.lsp.get_active_clients() -- cgit v1.2.3 From b524100f016de6b934894547d48f9ef811902397 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 9 Oct 2021 13:45:34 +0200 Subject: feat: support wildcard filetypes for null-ls providers (#1447) Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/lsp/utils.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lua/lsp/utils.lua') diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 87ba2337..59003406 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -1,16 +1,15 @@ local M = {} +local tbl = require "utils.table" + function M.is_client_active(name) local clients = vim.lsp.get_active_clients() - for _, client in pairs(clients) do - if client.name == name then - return true, client - end - end - return false + return tbl.find_first(clients, function(client) + return client.name == name + end) end -function M.get_active_client_by_ft(filetype) +function M.get_active_clients_by_ft(filetype) local matches = {} local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do @@ -22,7 +21,7 @@ function M.get_active_client_by_ft(filetype) return matches end -function M.get_ls_capabilities(client_id) +function M.get_client_capabilities(client_id) if not client_id then local buf_clients = vim.lsp.buf_get_clients() for _, buf_client in ipairs(buf_clients) do -- cgit v1.2.3