From f66654d5d5190865333e8e46474c1593302c558e Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Wed, 27 Mar 2024 18:31:14 +0200 Subject: [PATCH] feat(feline): improve feline lsp display (#688) * feat(feline): improve feline lsp display * docs: auto generate vimdoc * fix(feline): show the lsp names for the current buffer only --------- Co-authored-by: 89iuv <89iuv@users.noreply.github.com> --- README.md | 8 ++++ doc/catppuccin.txt | 8 ++++ lua/catppuccin/groups/integrations/feline.lua | 46 +++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7bb355f7..c2ddda40 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,14 @@ ctp_feline.setup({ ["rm"] = { "MORE", clrs.teal }, ["r?"] = { "CONFIRM", clrs.mauve }, ["!"] = { "SHELL", clrs.green }, + }, + view = { + lsp = { + progress = true, -- if true the status bar will display an lsp progress indicator + name = false, -- if true the status bar will display the lsp servers name, otherwise it will display the text "Lsp" + exclude_lsp_names = {}, -- lsp server names that should not be displayed when name is set to true + separator = "|", -- the separator used when there are multiple lsp servers + }, } }) ``` diff --git a/doc/catppuccin.txt b/doc/catppuccin.txt index 37d00518..e58428df 100644 --- a/doc/catppuccin.txt +++ b/doc/catppuccin.txt @@ -465,6 +465,14 @@ Here are the defaults: ["rm"] = { "MORE", clrs.teal }, ["r?"] = { "CONFIRM", clrs.mauve }, ["!"] = { "SHELL", clrs.green }, + }, + view = { + lsp = { + progress = true, -- if true the status bar will display an lsp progress indicator + name = false, -- if true the status bar will display the lsp servers name, otherwise it will display the text "Lsp" + exclude_lsp_names = {}, -- lsp server names that should not be displayed when name is set to true + separator = "|", -- the separator used when there are multiple lsp servers + }, } }) < diff --git a/lua/catppuccin/groups/integrations/feline.lua b/lua/catppuccin/groups/integrations/feline.lua index 68f431e1..4166841a 100644 --- a/lua/catppuccin/groups/integrations/feline.lua +++ b/lua/catppuccin/groups/integrations/feline.lua @@ -65,21 +65,40 @@ local mode_colors = { ["!"] = { "SHELL", C.green }, } +local view = { + lsp = { + progress = true, + name = false, + exclude_lsp_names = {}, + separator = "|", + }, +} + +local is_lsp_in_excluded_list = function(lsp_name) + for _, excluded_lsp in ipairs(view.lsp.exclude_lsp_names) do + if lsp_name == excluded_lsp then return true end + end + return false +end + function M.setup(opts) if opts then opts.assets = opts.assets or {} opts.sett = opts.sett or {} opts.mode_colors = opts.mode_colors or {} + opts.view = opts.view or {} else opts = { assets = {}, sett = {}, mode_colors = {}, + view = {}, } end assets = vim.tbl_deep_extend("force", assets, opts.assets) sett = vim.tbl_deep_extend("force", sett, opts.sett) mode_colors = vim.tbl_deep_extend("force", mode_colors, opts.mode_colors) + view = vim.tbl_deep_extend("force", view, opts.view) end function M.get() @@ -326,7 +345,7 @@ function M.get() return "" end, - enabled = is_enabled(80), + enabled = is_enabled(80) and view.lsp.progress == true, hl = { fg = C.rosewater, bg = sett.bkg, @@ -393,16 +412,33 @@ function M.get() components.active[3][2] = { provider = function() - if next(vim.lsp.buf_get_clients()) ~= nil then - return assets.lsp.server .. " " .. "Lsp" - else - return "" + local active_clients = vim.lsp.get_active_clients { bufnr = 0 } + + -- show an indicator that we have running lsps + if view.lsp.name == false and next(active_clients) ~= nil then return assets.lsp.server .. " " .. "Lsp" end + + -- show the actual name of the runing lsps + local lsp_names = "" + for index, lsp_config in ipairs(active_clients) do + if is_lsp_in_excluded_list(lsp_config.name) then goto continue end + + if index == 1 then + lsp_names = assets.lsp.server .. " " .. lsp_config.name + else + lsp_names = lsp_names .. view.lsp.separator .. lsp_config.name + end + + ::continue:: end + + return lsp_names end, + hl = { fg = sett.extras, bg = sett.bkg, }, + right_sep = invi_sep, }