32 lines
911 B
Lua
32 lines
911 B
Lua
--https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/ui.lua
|
|
|
|
---@class lib.lazyvim.ui
|
|
local M = {}
|
|
|
|
-- Optimized treesitter foldexpr for Neovim >= 0.10.0
|
|
function M.foldexpr()
|
|
local buf = vim.api.nvim_get_current_buf()
|
|
if vim.b[buf].ts_folds == nil then
|
|
-- as long as we don't have a filetype, don't bother checking if treesitter
|
|
-- is available (it won't be)
|
|
if vim.bo[buf].filetype == '' then
|
|
return '0'
|
|
end
|
|
if vim.bo[buf].filetype:find('dashboard') then
|
|
vim.b[buf].ts_folds = false
|
|
else
|
|
vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
|
|
end
|
|
end
|
|
|
|
return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or '0'
|
|
end
|
|
|
|
---@return {fg?:string}?
|
|
function M.fg(name)
|
|
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
|
|
local fg = hl and hl.fg or nil
|
|
return fg and { fg = string.format('#%06x', fg) } or nil
|
|
end
|
|
|
|
return M
|