···207207208208### lsp information
209209210210-lylla utils has a builtin helper for getting the current lsp client.
210210+lylla components has a builtin helper for getting the current lsp client.
211211212212```lua
213213-local utils = require("lylla.utils")
213213+local components = require("lylla.components")
214214215215{
216216 lylla.component(function()
217217- local client = utils.get_client()
218218- return client and {
217217+ local clients = components.lsp_clients()
218218+ return clients and {
219219 { { "lsp :: " }, { client } },
220220 }
221221- end, { events = { "FileType" } }),
221221+ end, { events = { "FileType", "LspAttach" } }),
222222}
223223```
224224
+28
lua/lylla/components.lua
···11+local components = {}
22+33+---@param props { buffer?: integer, limit?: integer, sep?: string, filter?: fun(client: vim.lsp.Client): boolean }
44+---@return string?
55+function components.lsp_clients(props)
66+ props = props or {}
77+ local buffer = props.buffer or 0
88+99+ local clients = vim
1010+ .iter(vim.lsp.get_clients({ bufnr = buffer }))
1111+ :map(function(
1212+ client --[[@as vim.lsp.Client]]
1313+ )
1414+ if props.filter and not props.filter(client) then
1515+ return
1616+ end
1717+ return client.config.name
1818+ end)
1919+ :totable()
2020+2121+ if #clients == 0 then
2222+ return
2323+ end
2424+2525+ return table.concat(clients, props.sep or " + ", 1, vim.F.if_nil(props.limit))
2626+end
2727+2828+return components
-14
lua/lylla/utils.lua
···11local utils = {}
2233-function utils.get_client()
44- local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
55- local result = vim.iter(vim.lsp.get_clients({ bufnr = 0 })):find(function(
66- client --[[@as vim.lsp.Client]]
77- )
88- return vim.iter(ipairs(client.config.filetypes)):any(function(_, ft)
99- return ft == buf_ft
1010- end)
1111- end)
1212- if result then
1313- return result.config.name
1414- end
1515-end
1616-173--- flatten list so all children have level of depth
184---@param lst table
195---@param maxdepth integer