🪴 a tiny, customizable statusline for neovim
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(utils): move lsp clients fn to separate components module

robin 9e7b3d43 5e933b29

+33 -19
+5 -5
README.md
··· 207 207 208 208 ### lsp information 209 209 210 - lylla utils has a builtin helper for getting the current lsp client. 210 + lylla components has a builtin helper for getting the current lsp client. 211 211 212 212 ```lua 213 - local utils = require("lylla.utils") 213 + local components = require("lylla.components") 214 214 215 215 { 216 216 lylla.component(function() 217 - local client = utils.get_client() 218 - return client and { 217 + local clients = components.lsp_clients() 218 + return clients and { 219 219 { { "lsp :: " }, { client } }, 220 220 } 221 - end, { events = { "FileType" } }), 221 + end, { events = { "FileType", "LspAttach" } }), 222 222 } 223 223 ``` 224 224
+28
lua/lylla/components.lua
··· 1 + local components = {} 2 + 3 + ---@param props { buffer?: integer, limit?: integer, sep?: string, filter?: fun(client: vim.lsp.Client): boolean } 4 + ---@return string? 5 + function components.lsp_clients(props) 6 + props = props or {} 7 + local buffer = props.buffer or 0 8 + 9 + local clients = vim 10 + .iter(vim.lsp.get_clients({ bufnr = buffer })) 11 + :map(function( 12 + client --[[@as vim.lsp.Client]] 13 + ) 14 + if props.filter and not props.filter(client) then 15 + return 16 + end 17 + return client.config.name 18 + end) 19 + :totable() 20 + 21 + if #clients == 0 then 22 + return 23 + end 24 + 25 + return table.concat(clients, props.sep or " + ", 1, vim.F.if_nil(props.limit)) 26 + end 27 + 28 + return components
-14
lua/lylla/utils.lua
··· 1 1 local utils = {} 2 2 3 - function utils.get_client() 4 - local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) 5 - local result = vim.iter(vim.lsp.get_clients({ bufnr = 0 })):find(function( 6 - client --[[@as vim.lsp.Client]] 7 - ) 8 - return vim.iter(ipairs(client.config.filetypes)):any(function(_, ft) 9 - return ft == buf_ft 10 - end) 11 - end) 12 - if result then 13 - return result.config.name 14 - end 15 - end 16 - 17 3 --- flatten list so all children have level of depth 18 4 ---@param lst table 19 5 ---@param maxdepth integer