diff --git a/lua/custom/plugins/fold.lua b/lua/custom/plugins/fold.lua new file mode 100644 index 00000000..6d15fb14 --- /dev/null +++ b/lua/custom/plugins/fold.lua @@ -0,0 +1,32 @@ +return { + "kevinhwang91/nvim-ufo", + event = { "User AstroFile", "InsertEnter" }, + dependencies = { "kevinhwang91/promise-async" }, + opts = { + preview = { + mappings = { + scrollB = "", + scrollF = "", + scrollU = "", + scrollD = "", + }, + }, + provider_selector = function(_, filetype, buftype) + local function handleFallbackException(bufnr, 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 (filetype == "" or buftype == "nofile") and "indent" -- only use indent until a file is opened + or function(bufnr) + return require("ufo") + .getFolds(bufnr, "lsp") + :catch(function(err) return handleFallbackException(bufnr, err, "treesitter") end) + :catch(function(err) return handleFallbackException(bufnr, err, "indent") end) + end + end, + }, + }