From 33b4d9da44491003cf5f1fc060aaca7034914fd6 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 29 Mar 2025 20:04:40 +0300 Subject: [PATCH] statusline/lualine: rewrite LSP client component --- .../plugins/statusline/lualine/lualine.nix | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/modules/plugins/statusline/lualine/lualine.nix b/modules/plugins/statusline/lualine/lualine.nix index bf070db7..4e69c852 100644 --- a/modules/plugins/statusline/lualine/lualine.nix +++ b/modules/plugins/statusline/lualine/lualine.nix @@ -239,35 +239,26 @@ in { { -- Lsp server name function() - local buf_ft = vim.api.nvim_get_option_value('filetype', {}) + local buf_ft = vim.bo.filetype + local excluded_buf_ft = { toggleterm = true, NvimTree = true, ["neo-tree"] = true, TelescopePrompt = true } - -- List of buffer types to exclude - local excluded_buf_ft = {"toggleterm", "NvimTree", "neo-tree", "TelescopePrompt"} - - -- Check if the current buffer type is in the excluded list - for _, excluded_type in ipairs(excluded_buf_ft) do - if buf_ft == excluded_type then - return "" + if excluded_buf_ft[buf_ft] then + return "" end + + local bufnr = vim.api.nvim_get_current_buf() + local clients = vim.lsp.get_clients({ bufnr = bufnr }) + + if vim.tbl_isempty(clients) then + return "No Active LSP" end - -- Get the name of the LSP server active in the current buffer - local clients = vim.lsp.get_active_clients() - local msg = 'No Active Lsp' - - -- if no lsp client is attached then return the msg - if next(clients) == nil then - return msg - end - + local active_clients = {} for _, client in ipairs(clients) do - local filetypes = client.config.filetypes - if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then - return client.name - end + table.insert(active_clients, client.name) end - return msg + return table.concat(active_clients, ", ") end, icon = ' ', separator = {left = ''},