aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/trouble.lua
blob: cc40587d6e50a4d805de92f69ef05426744faa55 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local icons = require "icons"

return {
    "folke/trouble.nvim",
    opts = function()
        local Util = require "trouble.util"
        return {
            modes = {
                symbols = {
                    win = {
                        position = "right",
                        size = 0.4,
                    },
                    format = "{symbol_kind} {symbol_pos:Comment} {symbol.name} {text:Comment}",
                    preview = {
                        type = "float",
                        relative = "editor",
                        border = "rounded",
                        title = "Preview",
                        title_pos = "center",
                        position = { 1, 0 },
                        size = { width = 0.3, height = 0.3 },
                        zindex = 200,
                    },
                },
                qflist = {
                    win = {
                        position = "right",
                        size = 0.4,
                    },
                    format = "{severity_icon|item.type:DiagnosticSignWarn} {text:ts} {pos:Comment}",
                    preview = {
                        type = "float",
                        relative = "editor",
                        border = "rounded",
                        title = "Preview",
                        title_pos = "center",
                        position = { 1, 0 },
                        size = { width = 0.3, height = 0.3 },
                        zindex = 200,
                    },
                },
                diagnostics = {
                    win = {
                        position = "down",
                        size = 0.4,
                    },
                    preview = {
                        type = "split",
                        relative = "win",
                        position = "right",
                        size = 0.5,
                    },
                },
            },
            icons = {
                kinds = icons.kinds,
            },
            formatters = {
                symbol_kind = function(ctx)
                    return { text = "[" .. ctx.item.kind .. "]", hl = "Type" }
                end,
                symbol_pos = function(ctx)
                    return "@ " .. ctx.item.pos[1] .. ":" .. (ctx.item.pos[2] + 1)
                end,
                severity_icon = function(ctx)
                    local severity = ctx.item.severity or vim.diagnostic.severity.ERROR
                    if not vim.diagnostic.severity[severity] then
                        return
                    end
                    if type(severity) == "string" then
                        severity = vim.diagnostic.severity[severity:upper()] or vim.diagnostic.severity.ERROR
                    end
                    local name = Util.camel(vim.diagnostic.severity[severity]:lower())
                    local sign = vim.fn.sign_getdefined("DiagnosticSign" .. name)[1]
                    local config = vim.diagnostic.config() or {}
                    if config.signs == nil or type(config.signs) == "boolean" then
                        return {
                            text = sign and "[" .. sign.text .. "]" or name:sub(1, 1),
                            hl = "DiagnosticSign" .. name,
                        }
                    end
                    local signs = config.signs or {}
                    if type(signs) == "function" then
                        signs = signs(0, 0) --[[@as vim.diagnostic.Opts.Signs]]
                    end
                    return {
                        text = type(signs) == "table" and signs.text and "[" .. signs.text[severity] .. "]"
                            or sign and sign.text
                            or name:sub(1, 1),
                        hl = "DiagnosticSign" .. name,
                    }
                end,
            },
            signs = true,
        }
    end,
    dependencies = { "nvim-tree/nvim-web-devicons" },
    keys = {
        {
            "<Leader>pe",
            "<cmd>Trouble diagnostics toggle win.position=bottom<CR>",
            desc = "Toggle diagnstostics panel",
        },
        { "<Leader>ps", "<cmd>Trouble symbols toggle<CR>", desc = "Toggle symbols panel" },
        { "<Leader>pq", "<cmd>Trouble qflist toggle<CR>", desc = "Toggle quickfix panel" },
    },
    cmd = { "Trouble" },
}