pojokcodeid.nvim-lazy/lua/custom/plugins/nvimufo.lua

203 lines
7.1 KiB
Lua
Raw Normal View History

2024-03-28 12:17:30 +07:00
return {
2024-04-09 05:51:53 +07:00
"kevinhwang91/nvim-ufo",
dependencies = {
"kevinhwang91/promise-async",
{
"luukvbaal/statuscol.nvim",
config = function()
local builtin = require("statuscol.builtin")
require("statuscol").setup({
-- relculright = true,
-- segments = {
-- { text = { builtin.foldfunc }, click = "v:lua.ScFa" },
-- { text = { "%s" }, click = "v:lua.ScSa" },
-- { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
-- },
setopt = true,
relculright = true,
segments = {
{ text = { "%s" }, click = "v:lua.ScSa" },
{
2024-04-12 07:56:50 +07:00
-- text = { builtin.foldfunc, " " },
text = { builtin.foldfunc },
2024-04-09 05:51:53 +07:00
condition = { builtin.not_empty, true, builtin.not_empty },
click = "v:lua.ScFa",
},
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
2024-04-12 07:44:49 +07:00
-- { text = { builtin.lnumfunc }, click = "v:lua.ScLa" },
2024-04-09 05:51:53 +07:00
},
})
end,
},
},
2024-04-12 10:48:32 +07:00
enabled = true,
2024-04-09 05:51:53 +07:00
lazy = true,
-- event = "BufReadPost",
event = { "BufReadPost", "BufRead", "InsertEnter", "BufNewFile" },
config = function()
vim.o.foldcolumn = "1" -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
2024-04-11 22:12:20 +07:00
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
2024-04-12 07:09:29 +07:00
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]]
2024-04-11 22:12:20 +07:00
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]]
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:󰛲,foldsep:│,foldclose:󰜄]]
2024-04-12 07:09:29 +07:00
-- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]]
2024-04-12 07:44:49 +07:00
vim.o.fillchars = [[eob: ,fold: ,foldopen:▾,foldsep:│,foldclose:▸]]
-- vim.opt.fillchars = {
-- vert = "▕", -- alternatives │
-- fold = " ",
-- eob = " ", -- suppress ~ at EndOfBuffer
-- diff = "", -- alternatives = ⣿ ░ ─
-- msgsep = "‾",
-- foldopen = "▾",
-- foldsep = "│",
-- foldclose = "▸",
-- }
2024-04-09 05:51:53 +07:00
-- these are "extra", change them as you like
vim.keymap.set("n", "zR", require("ufo").openAllFolds)
vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
vim.cmd("highlight FoldColumn guifg=" .. vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Comment")), "fg"))
2024-04-11 22:12:20 +07:00
-- vim.cmd("highlight FoldColumn guifg=" .. vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("IblIndent")), "fg"))
2024-04-09 05:51:53 +07:00
-- Option 3: treesitter as a main provider instead
-- Only depend on `nvim-treesitter/queries/filetype/folds.scm`,
-- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()`
2024-04-12 10:48:32 +07:00
-- require("ufo").setup({
-- -- provider_selector = function(bufnr, filetype, buftype)
-- -- return { "treesitter", "indent" }
-- -- end,
-- open_fold_hl_timeout = 150,
-- close_fold_kinds_for_ft = {
-- default = { "imports", "comment" },
-- json = { "array" },
-- c = { "comment", "region" },
-- },
-- preview = {
-- win_config = {
-- border = { "", "─", "", "", "", "─", "", "" },
-- -- winhighlight = 'Normal:Normal',
-- -- winhighlight = 'IncSearch:Folded',
-- winhighlight = "Normal:UfoPreviewNormal,FloatBorder:UfoPreviewBorder,CursorLine:UfoPreviewCursorLine",
-- winblend = 0,
-- },
-- mappings = {
-- scrollU = "<C-u>",
-- scrollD = "<C-d>",
-- jumpTop = "[",
-- jumpBot = "]",
-- },
-- },
-- provider_selector = function(_, filetype)
-- return { "treesitter", "indent" }
-- end,
-- fold_virt_text_handler = function(virt_text, lnum, end_lnum, width, truncate)
-- local result = {}
-- local _end = end_lnum - 1
-- local final_text = vim.trim(vim.api.nvim_buf_get_text(0, _end, 0, _end, -1, {})[1])
-- local suffix = final_text:format(end_lnum - lnum)
-- local suffix_width = vim.fn.strdisplaywidth(suffix)
-- local target_width = width - suffix_width
-- local cur_width = 0
-- for _, chunk in ipairs(virt_text) do
-- local chunk_text = chunk[1]
-- local chunk_width = vim.fn.strdisplaywidth(chunk_text)
-- if target_width > cur_width + chunk_width then
-- table.insert(result, chunk)
-- else
-- chunk_text = truncate(chunk_text, target_width - cur_width)
-- local hl_group = chunk[2]
-- table.insert(result, { chunk_text, hl_group })
-- chunk_width = vim.fn.strdisplaywidth(chunk_text)
-- -- str width returned from truncate() may less than 2nd argument, need padding
-- if cur_width + chunk_width < target_width then
-- suffix = suffix .. (" "):rep(target_width - cur_width - chunk_width)
-- end
-- break
-- end
-- cur_width = cur_width + chunk_width
-- end
-- table.insert(result, { " ⋯ ", "NonText" })
-- if vim.bo.filetype ~= "json" then
-- table.insert(result, { suffix, "TSPunctBracket" })
-- end
-- return result
-- end,
-- })
-- start ini bagian code support comment dan import
local ftMap = {
vim = "indent",
python = { "indent" },
git = "",
}
2024-04-09 05:51:53 +07:00
require("ufo").setup({
open_fold_hl_timeout = 150,
2024-04-12 10:48:32 +07:00
close_fold_kinds_for_ft = {
default = { "imports", "comment" },
json = { "array" },
c = { "comment", "region" },
},
2024-04-09 05:51:53 +07:00
preview = {
win_config = {
border = { "", "", "", "", "", "", "", "" },
2024-04-12 10:48:32 +07:00
winhighlight = "Normal:Folded",
2024-04-09 05:51:53 +07:00
winblend = 0,
},
mappings = {
scrollU = "<C-u>",
scrollD = "<C-d>",
jumpTop = "[",
jumpBot = "]",
},
},
2024-04-12 10:48:32 +07:00
provider_selector = function(bufnr, filetype, buftype)
-- if you prefer treesitter provider rather than lsp,
-- return ftMap[filetype] or {'treesitter', 'indent'}
return ftMap[filetype]
-- refer to ./doc/example.lua for detail
2024-04-09 05:51:53 +07:00
end,
2024-04-12 10:48:32 +07:00
2024-04-09 05:51:53 +07:00
fold_virt_text_handler = function(virt_text, lnum, end_lnum, width, truncate)
local result = {}
local _end = end_lnum - 1
local final_text = vim.trim(vim.api.nvim_buf_get_text(0, _end, 0, _end, -1, {})[1])
local suffix = final_text:format(end_lnum - lnum)
local suffix_width = vim.fn.strdisplaywidth(suffix)
local target_width = width - suffix_width
local cur_width = 0
for _, chunk in ipairs(virt_text) do
local chunk_text = chunk[1]
local chunk_width = vim.fn.strdisplaywidth(chunk_text)
if target_width > cur_width + chunk_width then
table.insert(result, chunk)
else
chunk_text = truncate(chunk_text, target_width - cur_width)
local hl_group = chunk[2]
table.insert(result, { chunk_text, hl_group })
chunk_width = vim.fn.strdisplaywidth(chunk_text)
-- str width returned from truncate() may less than 2nd argument, need padding
if cur_width + chunk_width < target_width then
suffix = suffix .. (" "):rep(target_width - cur_width - chunk_width)
end
break
end
cur_width = cur_width + chunk_width
end
table.insert(result, { "", "NonText" })
2024-04-12 10:48:32 +07:00
if string.match(virt_text[1][1], "import") then
return result
end
2024-04-12 08:57:11 +07:00
if vim.bo.filetype ~= "json" then
table.insert(result, { suffix, "TSPunctBracket" })
end
2024-04-09 05:51:53 +07:00
return result
end,
})
2024-04-12 10:48:32 +07:00
-- end bagian code support comment dan import
2024-04-09 05:51:53 +07:00
end,
2024-03-28 12:17:30 +07:00
}