---@class lazyvim.util.ui local M = {} function M.foldtext() local ok = pcall(vim.treesitter.get_parser, vim.api.nvim_get_current_buf()) local ret = ok and vim.treesitter.foldtext and vim.treesitter.foldtext() if not ret or type(ret) == "string" then ret = { { vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1], {} } } end table.insert(ret, { " " .. LazyVim.config.icons.misc.dots }) if not vim.treesitter.foldtext then return table.concat( vim.tbl_map(function(line) return line[1] end, ret), " " ) end return ret end ---@deprecated This is now setup by snacks.nvim function M.statuscolumn() return Snacks.statuscolumn() end ---@return {fg?:string}? function M.fg(name) local color = M.color(name) return color and { fg = color } or nil end ---@param name string ---@param bg? boolean ---@return string? function M.color(name, bg) ---@type {foreground?:number}? ---@diagnostic disable-next-line: deprecated local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name, link = false }) or vim.api.nvim_get_hl_by_name(name, true) ---@diagnostic disable-next-line: undefined-field ---@type string? local color = nil if hl then if bg then color = hl.bg or hl.background else color = hl.fg or hl.foreground end end return color and string.format("#%06x", color) or nil end M.skip_foldexpr = {} ---@type table local skip_check = assert(vim.uv.new_check()) function M.foldexpr() local buf = vim.api.nvim_get_current_buf() -- still in the same tick and no parser if M.skip_foldexpr[buf] then return "0" end -- don't use treesitter folds for terminal if vim.bo[buf].buftype == "terminal" then return "0" end -- as long as we don't have a filetype, don't bother -- checking if treesitter is available (it won't) if vim.bo[buf].filetype == "" then return "0" end local ok = pcall(vim.treesitter.get_parser, buf) if ok then return vim.treesitter.foldexpr() end -- no parser available, so mark it as skip -- in the next tick, all skip marks will be reset M.skip_foldexpr[buf] = true skip_check:start(function() M.skip_foldexpr = {} skip_check:stop() end) return "0" end return M