]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/trouble.lua
+use/op(nvim): tweak config
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / trouble.lua
1 -- A pretty diagnostics, references, telescope results, quickfix and location list
2 -- to help you solve all the trouble your code is causing.
3 -- https://github.com/folke/trouble.nvim
4 return {
5 "trouble.nvim",
6 cmd = { "Trouble" },
7 after = function()
8 local trouble = require("trouble")
9 trouble.setup({
10 auto_preview = true, -- automatically open preview when on an item
11 auto_refresh = true, -- auto refresh when open
12 auto_jump = false, -- auto jump to the item when there's only one
13 focus = false, -- Focus the window when opened
14 restore = true, -- restores the last location in the list when opening
15 follow = true, -- Follow the current item
16 indent_guides = true, -- show indent guides
17 max_items = 200, -- limit number of items that can be displayed per section
18 multiline = true, -- render multi-line messages
19 pinned = false, -- When pinned, the opened trouble window will be bound to the current buffer
20 warn_no_results = true, -- show a warning when there are no results
21 open_no_results = false, -- open the trouble window when there are no results
22 win = {}, -- window options for the results window. Can be a split or a floating window.
23 -- Window options for the preview window. Can be a split, floating window,
24 -- or `main` to show the preview in the main editor window.
25 preview = {
26 -- when a buffer is not yet loaded, the preview window will be created
27 -- in a scratch buffer with only syntax highlighting enabled.
28 -- Set to false, if you want the preview to always be a real loaded buffer.
29 scratch = false,
30 },
31 -- Throttle/Debounce settings. Should usually not be changed.
32 throttle = {
33 refresh = 20, -- fetches new data when needed
34 update = 10, -- updates the window
35 render = 10, -- renders the window
36 follow = 100, -- follows the current item
37 preview = { ms = 100, debounce = true }, -- shows the preview for the current item
38 },
39 -- Key mappings can be set to the name of a builtin action,
40 -- or you can define your own custom action.
41 keys = {
42 ["?"] = "help",
43 r = "refresh",
44 R = "toggle_refresh",
45 q = "close",
46 o = "jump_close",
47 ["<esc>"] = "cancel",
48 ["<cr>"] = "jump",
49 ["<2-leftmouse>"] = "jump",
50 ["<c-s>"] = "jump_split",
51 ["<c-v>"] = "jump_vsplit",
52 -- go down to next item (accepts count)
53 i = "prev",
54 ["}"] = "next",
55 ["]]"] = "next",
56 -- go up to prev item (accepts count)
57 k = "next",
58 ["{"] = "prev",
59 ["[["] = "prev",
60 dd = "delete",
61 d = { action = "delete", mode = "v" },
62 l = "inspect",
63 p = "preview",
64 P = "toggle_preview",
65 zo = "fold_open",
66 zO = "fold_open_recursive",
67 zc = "fold_close",
68 zC = "fold_close_recursive",
69 za = "fold_toggle",
70 zA = "fold_toggle_recursive",
71 zm = "fold_more",
72 zM = "fold_close_all",
73 zr = "fold_reduce",
74 zR = "fold_open_all",
75 zx = "fold_update",
76 zX = "fold_update_all",
77 zn = "fold_disable",
78 zN = "fold_enable",
79 zi = "fold_toggle_enable",
80 gb = { -- example of a custom action that toggles the active view filter
81 action = function(view)
82 view:filter({ buf = 0 }, { toggle = true })
83 end,
84 desc = "Toggle Current Buffer Filter",
85 },
86 s = { -- example of a custom action that toggles the severity
87 action = function(view)
88 local f = view:get_filter("severity")
89 local severity = ((f and f.filter.severity or 0) + 1) % 5
90 view:filter({ severity = severity }, {
91 id = "severity",
92 template = "{hl:Title}Filter:{hl} {severity}",
93 del = severity == 0,
94 })
95 end,
96 desc = "Toggle Severity Filter",
97 },
98 },
99 modes = {
100 diagnostics = {
101 auto_close = false, -- auto close when there are no items
102 auto_open = false, -- auto open when there are items
103 auto_preview = true, -- automatically open preview when on an item
104 auto_refresh = true, -- auto refresh when open
105 },
106 -- sources define their own modes, which you can use directly,
107 -- or override like in the example below
108 lsp_references = {
109 -- some modes are configurable, see the source code for more details
110 params = {
111 include_declaration = true,
112 },
113 },
114 -- The LSP base mode for:
115 -- * lsp_definitions, lsp_references, lsp_implementations
116 -- * lsp_type_definitions, lsp_declarations, lsp_command
117 lsp_base = {
118 params = {
119 -- don't include the current location in the results
120 include_current = false,
121 },
122 },
123 -- more advanced example that extends the lsp_document_symbols
124 symbols = {
125 desc = "document symbols",
126 mode = "lsp_document_symbols",
127 focus = false,
128 win = { position = "right" },
129 filter = {
130 -- remove Package since luals uses it for control flow structures
131 ["not"] = { ft = "lua", kind = "Package" },
132 any = {
133 -- all symbol kinds for help / markdown files
134 ft = { "help", "markdown" },
135 -- default set of symbol kinds
136 kind = {
137 "Class",
138 "Constructor",
139 "Enum",
140 "Field",
141 "Function",
142 "Interface",
143 "Method",
144 "Module",
145 "Namespace",
146 "Package",
147 "Property",
148 "Struct",
149 "Trait",
150 },
151 },
152 },
153 },
154 },
155 })
156 vim.keymap.set("n", "<C-j>", trouble.prev, {})
157 vim.keymap.set("n", "<C-l>", trouble.next, {})
158 end,
159 keys = {
160 {
161 "<leader>xx",
162 "<cmd>Trouble diagnostics toggle<cr>",
163 desc = "Diagnostics (Trouble)",
164 },
165 {
166 "<leader>xX",
167 "<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
168 desc = "Buffer Diagnostics (Trouble)",
169 },
170 {
171 "<leader>cs",
172 "<cmd>Trouble symbols toggle focus=false<cr>",
173 desc = "Symbols (Trouble)",
174 },
175 {
176 "<leader>cl",
177 "<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
178 desc = "LSP Definitions / references / ... (Trouble)",
179 },
180 {
181 "<leader>xL",
182 "<cmd>Trouble loclist toggle<cr>",
183 desc = "Location List (Trouble)",
184 },
185 {
186 "<leader>xQ",
187 "<cmd>Trouble qflist toggle<cr>",
188 desc = "Quickfix List (Trouble)",
189 },
190 },
191 }