summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins/nvim-ufo.lua
blob: 65f079a562b882e6de1a71a8334ff96c18390ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
return {
    {
        "kevinhwang91/nvim-ufo",
        event = "BufEnter",
        keys = {
            {
                "zR",
                function()
                    require("ufo").openAllFolds()
                end,
                desc = "ufo: open all folds",
            },
            {
                "zM",
                function()
                    require("ufo").closeAllFolds()
                end,
                desc = "ufo: close all folds",
            },
            {
                "zr",
                function()
                    require("ufo").openFoldsExceptKinds()
                end,
                desc = "ufo: open folds except kinds",
            },
            {
                "zm",
                function()
                    require("ufo").closeFoldsWith()
                end,
                desc = "ufo: close folds with"
            },
            {
                "zp",
                function()
                    require("ufo").peekFoldedLinesUnderCursor()
                end,
                desc = "ufo: peek fold"
            },
        },
        dependencies = {
            "kevinhwang91/promise-async",
        },
        opts = {
            preview = {
                mappings = {
                    scrollB = "<C-b>",
                    scrollF = "<C-f>",
                    scrollU = "<C-u>",
                    scrollD = "<C-d>",
                },
            },
            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,
        },
    }
}