-
Notifications
You must be signed in to change notification settings - Fork 163
/
init.lua
265 lines (250 loc) · 7.38 KB
/
init.lua
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
---@class trouble.Config.mod: trouble.Config
local M = {}
---@class trouble.Mode: trouble.Config,trouble.Section.spec
---@field desc? string
---@field sections? string[]
---@class trouble.Config
---@field mode? string
---@field config? fun(opts:trouble.Config)
---@field formatters? table<string,trouble.Formatter> custom formatters
---@field filters? table<string, trouble.FilterFn> custom filters
---@field sorters? table<string, trouble.SorterFn> custom sorters
local defaults = {
debug = false,
auto_close = false, -- auto close when there are no items
auto_open = false, -- auto open when there are items
auto_preview = true, -- automatically open preview when on an item
auto_refresh = true, -- auto refresh when open
focus = false, -- Focus the window when opened
follow = true, -- Follow the current item
indent_guides = true, -- show indent guides
max_items = 200, -- limit number of items that can be displayed per section
multiline = true, -- render multi-line messages
pinned = false, -- When pinned, the opened trouble window will be bound to the current buffer
---@type trouble.Window.opts
win = {}, -- window options for the results window. Can be a split or a floating window.
-- Window options for the preview window. Can be a split, floating window,
-- or `main` to show the preview in the main editor window.
---@type trouble.Window.opts
preview = { type = "main" },
-- Throttle/Debounce settings. Should usually not be changed.
---@type table<string, number|{ms:number, debounce?:boolean}>
throttle = {
refresh = 20, -- fetches new data when needed
update = 10, -- updates the window
render = 10, -- renders the window
follow = 10, -- follows the current item
preview = { ms = 100, debounce = true }, -- shows the preview for the current item
},
-- Key mappings can be set to the name of a builtin action,
-- or you can define your own custom action.
---@type table<string, string|trouble.Action>
keys = {
["?"] = "help",
r = "refresh",
R = "toggle_refresh",
q = "close",
o = "jump_close",
["<esc>"] = "cancel",
["<cr>"] = "jump",
["<2-leftmouse>"] = "jump",
["<c-s>"] = "jump_split",
["<c-v>"] = "jump_vsplit",
-- go down to next item (accepts count)
-- j = "next",
["}"] = "next",
["]]"] = "next",
-- go up to prev item (accepts count)
-- k = "prev",
["{"] = "prev",
["[["] = "prev",
i = "inspect",
p = "preview",
P = "toggle_preview",
zo = "fold_open",
zO = "fold_open_recursive",
zc = "fold_close",
zC = "fold_close_recursive",
za = "fold_toggle",
zA = "fold_toggle_recursive",
zm = "fold_more",
zM = "fold_close_all",
zr = "fold_reduce",
zR = "fold_open_all",
zx = "fold_update",
zX = "fold_update_all",
zn = "fold_disable",
zN = "fold_enable",
zi = "fold_toggle_enable",
},
---@type table<string, trouble.Mode>
modes = {
symbols = {
desc = "document symbols",
mode = "lsp_document_symbols",
focus = false,
win = { position = "right" },
filter = {
-- remove Package since luals uses it for control flow structures
["not"] = { ft = "lua", kind = "Package" },
any = {
-- all symbol kinds for help / markdown files
ft = { "help", "markdown" },
-- default set of symbol kinds
kind = {
"Class",
"Constructor",
"Enum",
"Field",
"Function",
"Interface",
"Method",
"Module",
"Namespace",
"Package",
"Property",
"Struct",
"Trait",
},
},
},
},
},
-- stylua: ignore
icons = {
---@type trouble.Indent.symbols
indent = {
top = "│ ",
middle = "├╴",
last = "└╴",
-- last = "-╴",
-- last = "╰╴", -- rounded
fold_open = " ",
fold_closed = " ",
ws = " ",
},
folder_closed = " ",
folder_open = " ",
kinds = {
Array = " ",
Boolean = " ",
Class = " ",
Constant = " ",
Constructor = " ",
Enum = " ",
EnumMember = " ",
Event = " ",
Field = " ",
File = " ",
Function = " ",
Interface = " ",
Key = " ",
Method = " ",
Module = " ",
Namespace = " ",
Null = " ",
Number = " ",
Object = " ",
Operator = " ",
Package = " ",
Property = " ",
String = " ",
Struct = " ",
TypeParameter = " ",
Variable = " ",
},
},
}
---@type trouble.Config
local options
---@param opts? trouble.Config
function M.setup(opts)
if vim.fn.has("nvim-0.9.2") == 0 then
local msg = "trouble.nvim requires Neovim >= 0.9.2"
vim.notify_once(msg, vim.log.levels.ERROR, { title = "trouble.nvim" })
error(msg)
return
end
opts = opts or {}
opts.mode = nil
options = {}
options = M.get(opts)
require("trouble.config.highlights").setup()
vim.api.nvim_create_user_command("Trouble", function(input)
require("trouble.command").execute(input)
end, {
nargs = "*",
complete = function(...)
return require("trouble.command").complete(...)
end,
desc = "Trouble",
})
require("trouble.view.main").setup()
return options
end
--- Update the default config.
--- Should only be used by source to extend the default config.
---@param config trouble.Config
function M.defaults(config)
options = vim.tbl_deep_extend("force", config, options)
end
function M.modes()
require("trouble.sources").load()
local ret = {} ---@type string[]
for k, v in pairs(options.modes) do
if v.source or v.mode or v.sections then
ret[#ret + 1] = k
end
end
table.sort(ret)
return ret
end
---@param ...? trouble.Config|string
---@return trouble.Config
function M.get(...)
options = options or M.setup()
-- check if we need to load sources
for i = 1, select("#", ...) do
---@type trouble.Config?
local opts = select(i, ...)
if type(opts) == "string" or (type(opts) == "table" and opts.mode) then
M.modes() -- trigger loading of sources
break
end
end
---@type trouble.Config[]
local all = { {}, defaults, options or {} }
---@type table<string, boolean>
local modes = {}
local first_mode ---@type string?
for i = 1, select("#", ...) do
---@type trouble.Config?
local opts = select(i, ...)
if type(opts) == "string" then
opts = { mode = opts }
end
if opts then
table.insert(all, opts)
local idx = #all
while opts.mode and not modes[opts.mode] do
first_mode = first_mode or opts.mode
modes[opts.mode or ""] = true
opts = options.modes[opts.mode] or {}
table.insert(all, idx, opts)
end
end
end
local ret = vim.tbl_deep_extend("force", unpack(all))
if type(ret.config) == "function" then
ret.config(ret)
end
ret.mode = first_mode
return ret
end
return setmetatable(M, {
__index = function(_, key)
options = options or M.setup()
assert(options, "should be setup")
return options[key]
end,
})