diff options
author | kylo252 <[email protected]> | 2021-10-03 16:13:46 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-03 16:13:46 +0200 |
commit | d01ba08eaec1640ac2d038893525b3ba0af25813 (patch) | |
tree | 5edf2f5a12cedacb32f0c5d45ec2d999dacb99cd /lua/core/info.lua | |
parent | 3e1cd1ec235404ae96ed2d0756729cf44ae48f3e (diff) |
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.
Diffstat (limited to 'lua/core/info.lua')
-rw-r--r-- | lua/core/info.lua | 87 |
1 files changed, 38 insertions, 49 deletions
diff --git a/lua/core/info.lua b/lua/core/info.lua index b8d51a8c..ff024fa5 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -10,6 +10,7 @@ local M = { } local fmt = string.format +local text = require "interface.text" local function str_list(list) return fmt("[ %s ]", table.concat(list, ", ")) @@ -65,44 +66,55 @@ local function tbl_set_highlight(terms, highlight_group) end end +local function make_client_info(client) + local client_enabled_caps = require("lsp.utils").get_ls_capabilities(client.id) + local name = client.name + local id = client.id + local document_formatting = client.resolved_capabilities.document_formatting + local client_info = { + fmt("* Name: %s", name), + fmt("* Id: %s", tostring(id)), + fmt("* Supports formatting: %s", tostring(document_formatting)), + } + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* Capabilities list: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_right(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(client_info, enabled_caps) + end + + return client_info +end + function M.toggle_popup(ft) local lsp_utils = require "lsp.utils" - local client = lsp_utils.get_active_client_by_ft(ft) - local is_client_active = false - local client_enabled_caps = {} - local client_name = "" - local client_id = 0 - local document_formatting = false - if client ~= nil then - is_client_active = not client.is_stopped() - client_enabled_caps = require("lsp").get_ls_capabilities(client.id) - client_name = client.name - client_id = client.id - document_formatting = client.resolved_capabilities.document_formatting - end + local clients = lsp_utils.get_active_client_by_ft(ft) + local client_names = {} local header = { fmt("Detected filetype: %s", ft), fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)), } - local text = require "interface.text" local lsp_info = { "Language Server Protocol (LSP) info", - fmt("* Associated server: %s", client_name), - fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id), - fmt("* Supports formatting: %s", tostring(document_formatting)), + fmt "* Associated server(s):", } - if not vim.tbl_isempty(client_enabled_caps) then - local caps_text = "* Capabilities list: " - local caps_text_len = caps_text:len() - local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") - enabled_caps = text.shift_right(enabled_caps, caps_text_len) - enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) - vim.list_extend(lsp_info, enabled_caps) + + for _, client in pairs(clients) do + vim.list_extend(lsp_info, make_client_info(client)) + table.insert(client_names, client.name) end - local null_ls = require "lsp.null-ls" - local registered_providers = null_ls.list_supported_provider_names(ft) + + local null_formatters = require "lsp.null-ls.formatters" + local null_linters = require "lsp.null-ls.linters" + local registered_formatters = null_formatters.list_supported_names(ft) + local registered_linters = null_linters.list_supported_names(ft) + local registered_providers = {} + vim.list_extend(registered_providers, registered_formatters) + vim.list_extend(registered_providers, registered_linters) local registered_count = vim.tbl_count(registered_providers) local null_ls_info = { "Formatters and linters", @@ -113,24 +125,6 @@ function M.toggle_popup(ft) ), } - local null_formatters = require "lsp.null-ls.formatters" - local missing_formatters = null_formatters.list_unsupported_names(ft) - local missing_formatters_status = {} - if not vim.tbl_isempty(missing_formatters) then - missing_formatters_status = { - fmt("* Missing formatters: %s", table.concat(missing_formatters, " ï™— , ") .. " ï™— "), - } - end - - local null_linters = require "lsp.null-ls.linters" - local missing_linters = null_linters.list_unsupported_names(ft) - local missing_linters_status = {} - if not vim.tbl_isempty(missing_linters) then - missing_linters_status = { - fmt("* Missing linters: %s", table.concat(missing_linters, " ï™— , ") .. " ï™— "), - } - end - local content_provider = function(popup) local content = {} @@ -143,8 +137,6 @@ function M.toggle_popup(ft) lsp_info, { "" }, null_ls_info, - missing_formatters_status, - missing_linters_status, { "" }, { "" }, get_formatter_suggestion_msg(ft), @@ -167,11 +159,8 @@ function M.toggle_popup(ft) vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' tbl_set_highlight(registered_providers, "LvimInfoIdentifier") - tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") - tbl_set_highlight(missing_linters, "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier") - vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end local Popup = require("interface.popup"):new { |