function TABLE_CONTAINS(tbl, x) local found = false for _, v in pairs(tbl) do if v == x then found = true end end return found end local icons = vim.g.pcode_icons.folding local M = {} if pcode.nvimufo then M.ufo = { "kevinhwang91/nvim-ufo", dependencies = { "kevinhwang91/promise-async", { "luukvbaal/statuscol.nvim", config = function() local builtin = require("statuscol.builtin") require("statuscol").setup({ setopt = true, relculright = true, segments = { { text = { "%s" }, click = "v:lua.ScSa" }, { text = { builtin.foldfunc }, condition = { builtin.not_empty, true, builtin.not_empty }, click = "v:lua.ScFa", }, { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, }, }) end, }, }, enabled = true, lazy = true, event = "VeryLazy", 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:]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:󰛲,foldsep:│,foldclose:󰜄]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep:│,foldclose:]] -- vim.o.fillchars = [[eob: ,fold: ,foldopen:▾,foldsep:│,foldclose:▸]] vim.opt.fillchars = { vert = icons.vert, fold = icons.fold, eob = icons.eob, diff = icons.diff, msgsep = icons.msgsep, foldopen = icons.foldopen, foldsep = icons.foldsep, foldclose = icons.foldclose, } -- 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")) -- start ini bagian code support comment dan import local ftMap = { vim = "indent", python = { "indent" }, git = "", } local function customizeSelector(bufnr) local function handleFallbackException(err, providerName) if type(err) == "string" and err:match("UfoFallbackException") then return require("ufo").getFolds(bufnr, providerName) else return require("promise").reject(err) end end return require("ufo") .getFolds(bufnr, "lsp") :catch(function(err) return handleFallbackException(err, "treesitter") end) :catch(function(err) return handleFallbackException(err, "indent") end) end require("ufo").setup({ open_fold_hl_timeout = 150, close_fold_kinds_for_ft = { -- default = { "imports", "comment" }, -- json = { "array" }, -- c = { "comment", "region" }, }, preview = { win_config = { border = { "", "─", "", "", "", "─", "", "" }, winhighlight = "Normal:Folded", winblend = 0, }, mappings = { scrollU = "", scrollD = "", jumpTop = "[", jumpBot = "]", }, }, provider_selector = function(bufnr, filetype, buftype) return ftMap[filetype] or customizeSelector end, fold_virt_text_handler = function(virt_text, lnum, end_lnum, width, truncate) local result = {} local closed_fold_text = "comments ..." -- Teks yang ingin ditampilkan local import_fold_text = "import ..." -- Teks yang ingin ditampilkan local is_comment = false -- Variabel untuk mengecek apakah ini komentar local is_import = false local is_bracket = false -- Memeriksa apakah baris awal dari fold adalah komentar local start_line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1] -- cari comentar dengan awalan /* untuk generaal comment if start_line:find("^%s*%/%*") then is_comment = true -- cara commentar dengan awalan