forked from Bekaboo/dropbar.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.lua
934 lines (911 loc) · 28.3 KB
/
configs.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
local utils = require('dropbar.utils')
local api = require('dropbar.api')
local M = {}
---@class dropbar_configs_t
M.opts = {
icons = {
enable = true,
kinds = {
---Directory icon and highlighting getter, set to empty string to disable
---@param path string path to the directory
---@return string: icon for the directory
---@return string?: highlight group for the icon
---@type fun(path: string): string, string?|string?
dir_icon = function(_)
return M.opts.icons.kinds.symbols.Folder, 'DropBarIconKindFolder'
end,
---File icon and highlighting getter, set to empty string to disable
---@param path string path to the file
---@return string: icon for the file
---@return string?: highlight group for the icon
---@type fun(path: string): string, string?|string?
file_icon = function(path)
local icon_kind_opts = M.opts.icons.kinds
local file_icon = icon_kind_opts.symbols.File
local file_icon_hl = 'DropBarIconKindFile'
local devicons_ok, devicons = pcall(require, 'nvim-web-devicons')
if not devicons_ok then
return file_icon, file_icon_hl
end
-- Try to find icon using the filename, explicitly disable the
-- default icon so that we can try to find the icon using the
-- filetype if the filename does not have a corresponding icon
local devicon, devicon_hl = devicons.get_icon(
vim.fs.basename(path),
vim.fn.fnamemodify(path, ':e'),
{ default = false }
)
-- No corresponding devicon found using the filename, try finding icon
-- with filetype if the file is loaded as a buf in nvim
if not devicon then
---@type integer?
local buf = vim.iter(vim.api.nvim_list_bufs()):find(function(buf)
return vim.api.nvim_buf_get_name(buf) == path
end)
if buf then
local filetype =
vim.api.nvim_get_option_value('filetype', { buf = buf })
devicon, devicon_hl = devicons.get_icon_by_filetype(filetype)
end
end
file_icon = devicon and devicon .. ' ' or file_icon
file_icon_hl = devicon_hl
return file_icon, file_icon_hl
end,
symbols = {
Array = ' ',
Boolean = ' ',
BreakStatement = ' ',
Call = ' ',
CaseStatement = ' ',
Class = ' ',
Color = ' ',
Constant = ' ',
Constructor = ' ',
ContinueStatement = '→ ',
Copilot = ' ',
Declaration = ' ',
Delete = ' ',
DoStatement = ' ',
Element = ' ',
Enum = ' ',
EnumMember = ' ',
Event = ' ',
Field = ' ',
File = ' ',
Folder = ' ',
ForStatement = ' ',
Function = ' ',
H1Marker = ' ',
H2Marker = ' ',
H3Marker = ' ',
H4Marker = ' ',
H5Marker = ' ',
H6Marker = ' ',
Identifier = ' ',
IfStatement = ' ',
Interface = ' ',
Keyword = ' ',
List = ' ',
Log = ' ',
Lsp = ' ',
Macro = ' ',
MarkdownH1 = ' ',
MarkdownH2 = ' ',
MarkdownH3 = ' ',
MarkdownH4 = ' ',
MarkdownH5 = ' ',
MarkdownH6 = ' ',
Method = ' ',
Module = ' ',
Namespace = ' ',
Null = ' ',
Number = ' ',
Object = ' ',
Operator = ' ',
Package = ' ',
Pair = ' ',
Property = ' ',
Reference = ' ',
Regex = ' ',
Repeat = ' ',
RuleSet = ' ',
Scope = ' ',
Snippet = ' ',
Specifier = ' ',
Statement = ' ',
String = ' ',
Struct = ' ',
SwitchStatement = ' ',
Terminal = ' ',
Text = ' ',
Type = ' ',
TypeParameter = ' ',
Unit = ' ',
Value = ' ',
Variable = ' ',
WhileStatement = ' ',
},
},
ui = {
bar = {
separator = ' ',
extends = '…',
},
menu = {
separator = ' ',
indicator = ' ',
},
},
},
symbol = {
---@type fun(symbol: dropbar_symbol_t, min_width: integer?, n_clicks: integer?, button: string?, modifiers: string?)|false?
on_click = function(symbol)
-- Update current context highlights if the symbol
-- is shown inside a menu
if symbol.entry and symbol.entry.menu then
symbol.entry.menu:update_current_context_hl(symbol.entry.idx)
elseif symbol.bar then
symbol.bar:update_current_context_hl(symbol.bar_idx)
end
-- Determine menu configs
local prev_win = nil ---@type integer?
local prev_buf = nil ---@type integer?
local entries_source = nil ---@type dropbar_symbol_t[]?
local init_cursor = nil ---@type integer[]?
local win_configs = {}
if symbol.bar then -- If symbol inside a dropbar
prev_win = symbol.bar.win
prev_buf = symbol.bar.buf
entries_source = symbol.opts.siblings
init_cursor = symbol.opts.sibling_idx
and { symbol.opts.sibling_idx, 0 }
if symbol.bar.in_pick_mode then
---@param tbl number[]
local function tbl_sum(tbl)
local sum = 0
for _, v in ipairs(tbl) do
sum = sum + v
end
return sum
end
win_configs.relative = 'win'
win_configs.win = vim.api.nvim_get_current_win()
win_configs.row = 0
win_configs.col = symbol.bar.padding.left
+ tbl_sum(vim.tbl_map(
function(component)
return component:displaywidth()
+ symbol.bar.separator:displaywidth()
end,
vim.tbl_filter(function(component)
return component.bar_idx < symbol.bar_idx
end, symbol.bar.components)
))
end
elseif symbol.entry and symbol.entry.menu then -- If inside a menu
prev_win = symbol.entry.menu.win
prev_buf = symbol.entry.menu.buf
entries_source = symbol.opts.children
end
-- Toggle existing menu
if symbol.menu then
symbol.menu:toggle({
prev_win = prev_win,
prev_buf = prev_buf,
win_configs = win_configs,
})
return
end
-- Create a new menu for the symbol
if not entries_source or vim.tbl_isempty(entries_source) then
return
end
local menu = require('dropbar.menu')
local configs = require('dropbar.configs')
symbol.menu = menu.dropbar_menu_t:new({
prev_win = prev_win,
prev_buf = prev_buf,
cursor = init_cursor,
win_configs = win_configs,
---@param sym dropbar_symbol_t
entries = vim.tbl_map(function(sym)
local menu_indicator_icon = configs.opts.icons.ui.menu.indicator
local menu_indicator_on_click = nil
if not sym.children or vim.tbl_isempty(sym.children) then
menu_indicator_icon =
string.rep(' ', vim.fn.strdisplaywidth(menu_indicator_icon))
menu_indicator_on_click = false
end
return menu.dropbar_menu_entry_t:new({
components = {
sym:merge({
name = '',
icon = menu_indicator_icon,
icon_hl = 'dropbarIconUIIndicator',
on_click = menu_indicator_on_click,
}),
sym:merge({
on_click = function()
local current_menu = symbol.menu
while current_menu and current_menu.prev_menu do
current_menu = current_menu.prev_menu
end
if current_menu then
current_menu:close(false)
end
sym:jump()
end,
}),
},
})
end, entries_source),
})
symbol.menu:toggle()
end,
preview = {
---Reorient the preview window on previewing a new symbol
---@param _ integer source window id, ignored
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(_, range)
local invisible = range['end'].line - vim.fn.line('w$') + 1
if invisible > 0 then
local view = vim.fn.winsaveview() --[[@as vim.fn.winrestview.dict]]
view.topline = math.min(
view.topline + invisible,
math.max(1, range.start.line - vim.wo.scrolloff + 1)
)
vim.fn.winrestview(view)
end
end,
},
jump = {
---@param win integer source window id
---@param range {start: {line: integer}, end: {line: integer}} 0-indexed
reorient = function(win, range)
local view = vim.fn.winsaveview()
local win_height = vim.api.nvim_win_get_height(win)
local topline = range.start.line - math.floor(win_height / 4)
if
topline > view.topline
and topline + win_height < vim.fn.line('$')
then
view.topline = topline
vim.fn.winrestview(view)
end
end,
},
},
bar = {
---@type boolean|fun(buf: integer, win: integer, info: table?): boolean
enable = function(buf, win, _)
if
not vim.api.nvim_buf_is_valid(buf)
or not vim.api.nvim_win_is_valid(win)
or vim.fn.win_gettype(win) ~= ''
or vim.wo[win].winbar ~= ''
or vim.bo[buf].ft == 'help'
then
return false
end
local stat = vim.uv.fs_stat(vim.api.nvim_buf_get_name(buf))
if stat and stat.size > 1024 * 1024 then
return false
end
return vim.bo[buf].ft == 'markdown'
or pcall(vim.treesitter.get_parser, buf)
or not vim.tbl_isempty(vim.lsp.get_clients({
bufnr = buf,
method = 'textDocument/documentSymbol',
}))
end,
attach_events = {
'BufWinEnter',
'BufWritePost',
},
-- Wait for a short time before updating the winbar, if another update
-- request is received within this time, the previous request will be
-- cancelled, this improves the performance when the user is holding
-- down a key (e.g. 'j') to scroll the window, default to 0 ms
-- If you encounter performance issues when scrolling the window, try
-- setting this option to a number slightly larger than
-- 1000 / key_repeat_rate
update_debounce = 0,
update_events = {
win = {
'CursorMoved',
'WinResized',
},
buf = {
'BufModifiedSet',
'FileChangedShellPost',
'TextChanged',
'ModeChanged',
},
global = {
'DirChanged',
'VimResized',
},
},
hover = true,
---@type dropbar_source_t[]|fun(buf: integer, win: integer): dropbar_source_t[]
sources = function(buf, _)
local sources = require('dropbar.sources')
if vim.bo[buf].ft == 'markdown' then
return {
sources.path,
sources.markdown,
}
end
if vim.bo[buf].buftype == 'terminal' then
return {
sources.terminal,
}
end
return {
sources.path,
utils.source.fallback({
sources.lsp,
sources.treesitter,
}),
}
end,
padding = {
left = 1,
right = 1,
},
pick = {
pivots = 'abcdefghijklmnopqrstuvwxyz',
},
truncate = true,
},
menu = {
-- When on, preview the symbol under the cursor on CursorMoved
preview = true,
-- When on, automatically set the cursor to the closest previous/next
-- clickable component in the direction of cursor movement on CursorMoved
quick_navigation = true,
entry = {
padding = {
left = 1,
right = 1,
},
},
-- Menu scrollbar options
scrollbar = {
enable = true,
-- The background / gutter of the scrollbar
-- When false, only the thumb is shown.
background = true,
},
---@type table<string, string|function|table<string, string|function>>
keymaps = {
['q'] = '<C-w>q',
['<Esc>'] = '<C-w>q',
['<LeftMouse>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
local clicked_menu = utils.menu.get({ win = mouse.winid })
-- If clicked on a menu, invoke the corresponding click action,
-- else close all menus and set the cursor to the clicked window
if clicked_menu then
clicked_menu:click_at({ mouse.line, mouse.column - 1 }, nil, 1, 'l')
return
end
utils.menu.exec('close')
utils.bar.exec('update_current_context_hl')
if vim.api.nvim_win_is_valid(mouse.winid) then
vim.api.nvim_set_current_win(mouse.winid)
end
end,
['<CR>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local cursor = vim.api.nvim_win_get_cursor(menu.win)
local component = menu.entries[cursor[1]]:first_clickable(cursor[2])
if component then
menu:click_on(component, nil, 1, 'l')
end
end,
['<MouseMove>'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
utils.menu.update_hover_hl(mouse)
if M.opts.menu.preview then
utils.menu.update_preview(mouse)
end
end,
['i'] = function()
local menu = utils.menu.get_current()
if not menu then
return
end
menu:fuzzy_find_open()
end,
},
---@alias dropbar_menu_win_config_opts_t any|fun(menu: dropbar_menu_t):any
---@type table<string, dropbar_menu_win_config_opts_t>
---@see vim.api.nvim_open_win
win_configs = {
border = 'none',
style = 'minimal',
row = function(menu)
return menu.prev_menu
and menu.prev_menu.clicked_at
and menu.prev_menu.clicked_at[1] - vim.fn.line('w0')
or 0
end,
---@param menu dropbar_menu_t
col = function(menu)
if menu.prev_menu then
return menu.prev_menu._win_configs.width
+ (
menu.prev_menu.scrollbar
and menu.prev_menu.scrollbar.background
and 1
or 0
)
end
local mouse = vim.fn.getmousepos()
local bar = utils.bar.get({ win = menu.prev_win })
if not bar then
return mouse.wincol
end
local _, range = bar:get_component_at(math.max(0, mouse.wincol - 1))
return range and range.start or mouse.wincol
end,
relative = 'win',
win = function(menu)
return menu.prev_menu and menu.prev_menu.win
or vim.fn.getmousepos().winid
end,
height = function(menu)
return math.max(
1,
math.min(
#menu.entries,
vim.go.pumheight ~= 0 and vim.go.pumheight
or math.ceil(vim.go.lines / 4)
)
)
end,
width = function(menu)
local min_width = vim.go.pumwidth ~= 0 and vim.go.pumwidth or 8
if vim.tbl_isempty(menu.entries) then
return min_width
end
return math.max(
min_width,
math.max(unpack(vim.tbl_map(function(entry)
return entry:displaywidth()
end, menu.entries)))
)
end,
zindex = function(menu)
if menu.prev_menu then
if menu.prev_menu.scrollbar and menu.prev_menu.scrollbar.thumb then
return vim.api.nvim_win_get_config(menu.prev_menu.scrollbar.thumb).zindex
end
return vim.api.nvim_win_get_config(menu.prev_win).zindex
end
end,
},
},
fzf = {
win_configs = {
relative = 'win',
anchor = 'NW',
height = 1,
win = function(menu)
return menu.win
end,
width = function(menu)
local function border_width(border)
if type(border) == 'string' then
if border == 'none' or border == 'shadow' then
return 0
end
return 2 -- left and right border
end
local left, right = 1, 1
if
(#border == 1 and border[1] == '')
or (#border == 4 and border[4] == '')
or (#border == 8 and border[8] == '')
then
left = 0
end
if
(#border == 1 and border[1] == '')
or (#border == 4 and border[4] == '')
or (#border == 8 and border[4] == '')
then
right = 0
end
return left + right
end
local menu_width = menu._win_configs.width
+ border_width(menu._win_configs.border)
local self_width = menu._win_configs.width
local self_border = border_width(
(
M.opts.fzf.win_configs
and M.eval(M.opts.fzf.win_configs.border, menu)
)
or (menu.fzf_win_configs and M.eval(
menu.fzf_win_configs.border,
menu
))
or menu._win_configs.border
)
if self_width + self_border > menu_width then
return self_width - self_border
else
return menu_width - self_border
end
end,
row = function(menu)
local menu_border = menu._win_configs.border
if
type(menu_border) == 'string'
and menu_border ~= 'shadow'
and menu_border ~= 'none'
then
return menu._win_configs.height + 1
elseif menu_border == 'none' then
return menu._win_configs.height
end
local len_menu_border = #menu_border
if
len_menu_border == 1 and menu_border[1] ~= ''
or (len_menu_border == 2 or len_menu_border == 4) and menu_border[2] ~= ''
or len_menu_border == 8 and menu_border[8] ~= ''
then
return menu._win_configs.height + 1
else
return menu._win_configs.height
end
end,
col = function(menu)
local menu_border = menu._win_configs.border
if
type(menu_border) == 'string'
and menu_border ~= 'shadow'
and menu_border ~= 'none'
then
return -1
end
if
type(menu_border) == 'table' and menu_border[#menu_border] ~= ''
then
return -1
end
return 0
end,
},
---@type table<string, string | fun()>
keymaps = {
['<LeftMouse>'] = function()
---@type dropbar_menu_t
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
if not mouse then
return
end
if mouse.winid ~= menu.win then
local default_func = M.opts.menu.keymaps['<LeftMouse>']
if type(default_func) == 'function' then
default_func()
end
menu:fuzzy_find_close()
return
elseif mouse.winrow > vim.api.nvim_buf_line_count(menu.buf) then
return
end
vim.api.nvim_win_set_cursor(menu.win, { mouse.line, mouse.column - 1 })
menu:fuzzy_find_click_on_entry(function(entry)
return entry:get_component_at(mouse.column - 1, true)
end)
end,
['<MouseMove>'] = function()
---@type dropbar_menu_t
local menu = utils.menu.get_current()
if not menu then
return
end
local mouse = vim.fn.getmousepos()
if not mouse then
return
end
-- If mouse is not in the menu window or on the border, end preview
-- and clear hover highlights
if
mouse.winid ~= menu.win
or mouse.line <= 0
or mouse.column <= 0
or mouse.winrow > (#menu.entries + 1)
then
-- Find the root menu
while menu and menu.prev_menu do
menu = menu.prev_menu
end
if menu then
menu:finish_preview(true)
menu:update_hover_hl()
end
return
end
if M.opts.menu.preview then
menu:preview_symbol_at({ mouse.line, mouse.column - 1 }, true)
end
menu:update_hover_hl({ mouse.line, mouse.column - 1 })
end,
['<Up>'] = api.fuzzy_find_prev,
['<Down>'] = api.fuzzy_find_next,
['<C-k>'] = api.fuzzy_find_prev,
['<C-j>'] = api.fuzzy_find_next,
['<C-p>'] = api.fuzzy_find_prev,
['<C-n>'] = api.fuzzy_find_next,
['<CR>'] = api.fuzzy_find_click,
['<S-Enter>'] = function()
api.fuzzy_find_click(-1)
end,
},
prompt = '%#htmlTag# ',
char_pattern = '[%w%p]',
retain_inner_spaces = true,
fuzzy_find_on_click = true,
},
sources = {
path = {
max_depth = 16,
---@type string|fun(buf: integer, win: integer): string
relative_to = function(_, win)
-- Workaround for Vim:E5002: Cannot find window number
local ok, cwd = pcall(vim.fn.getcwd, win)
return ok and cwd or vim.fn.getcwd()
end,
---Can be used to filter out files or directories
---based on their name
---@type fun(name: string): boolean
filter = function(_)
return true
end,
---Last symbol from path source when current buf is modified
---@param sym dropbar_symbol_t
---@return dropbar_symbol_t
modified = function(sym)
return sym
end,
---@type boolean|fun(path: string): boolean?|nil
preview = true,
},
treesitter = {
max_depth = 16,
-- Vim regex used to extract a short name from the node text
-- word with optional prefix and suffix: [#~!@\*&.]*[[:keyword:]]\+!\?
-- word separators: \(->\)\+\|-\+\|\.\+\|:\+\|\s\+
name_regex = [=[[#~!@\*&.]*[[:keyword:]]\+!\?]=]
.. [=[\(\(\(->\)\+\|-\+\|\.\+\|:\+\|\s\+\)\?[#~!@\*&.]*[[:keyword:]]\+!\?\)*]=],
-- The order matters! The first match is used as the type
-- of the treesitter symbol and used to show the icon
-- Types listed below must have corresponding icons
-- in the `icons.kinds.symbols` table for the icon to be shown
valid_types = {
'array',
'boolean',
'break_statement',
'call',
'case_statement',
'class',
'constant',
'constructor',
'continue_statement',
'delete',
'do_statement',
'element',
'enum',
'enum_member',
'event',
'for_statement',
'function',
'h1_marker',
'h2_marker',
'h3_marker',
'h4_marker',
'h5_marker',
'h6_marker',
'if_statement',
'interface',
'keyword',
'macro',
'method',
'module',
'namespace',
'null',
'number',
'operator',
'package',
'pair',
'property',
'reference',
'repeat',
'rule_set',
'scope',
'specifier',
'struct',
'switch_statement',
'type',
'type_parameter',
'unit',
'value',
'variable',
'while_statement',
'declaration',
'field',
'identifier',
'object',
'statement',
},
},
lsp = {
max_depth = 16,
valid_symbols = {
'File',
'Module',
'Namespace',
'Package',
'Class',
'Method',
'Property',
'Field',
'Constructor',
'Enum',
'Interface',
'Function',
'Variable',
'Constant',
'String',
'Number',
'Boolean',
'Array',
'Object',
'Keyword',
'Null',
'EnumMember',
'Struct',
'Event',
'Operator',
'TypeParameter',
},
request = {
-- Times to retry a request before giving up
ttl_init = 60,
interval = 1000, -- in ms
},
},
markdown = {
max_depth = 6,
parse = {
-- Number of lines to update when cursor moves out of the parsed range
look_ahead = 200,
},
},
terminal = {
---@type string|fun(buf: integer): string
icon = function(_)
return M.opts.icons.kinds.symbols.Terminal or ' '
end,
---@type string|fun(buf: integer): string
name = vim.api.nvim_buf_get_name,
---@type boolean
---Show the current terminal buffer in the menu
show_current = true,
},
},
}
---Set dropbar options
---@param new_opts dropbar_configs_t?
function M.set(new_opts)
new_opts = new_opts or {}
local islist = vim.islist or vim.tbl_islist
-- Notify deprecated options
if new_opts.general and islist(new_opts.general.update_events) then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.general.update_events', 'WarningMsg' },
{ ' is deprecated, please use:\n', 'Normal' },
{ ' opts.general.update_events.win', 'WarningMsg' },
{ ' for updating a winbar attached to a single window,\n', 'Normal' },
{ ' opts.general.update_events.buf ', 'WarningMsg' },
{ 'for updating all winbars attached to a buffer, or\n', 'Normal' },
{ ' opts.general.update_events.global ', 'WarningMsg' },
{ 'for updating all winbars in current nvim session ', 'Normal' },
{ 'instead', 'Normal' },
}, true, {})
new_opts.general.update_events = {
win = new_opts.general.update_events,
}
end
if ((new_opts.sources or {}).treesitter or {}).name_pattern then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.sources.treesitter.name_pattern', 'WarningMsg' },
{ ' is deprecated.\n', 'Normal' },
{ '[dropbar.nvim] ', 'Normal' },
{ 'Please use ', 'Normal' },
{ 'opts.sources.treesitter.name_regex ', 'WarningMsg' },
{ 'instead to match ts node names with vim regex', 'Normal' },
}, true, {})
new_opts.sources.treesitter.name_pattern = nil
end
if (new_opts.general or {}).update_interval then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.general.update_interval', 'WarningMsg' },
{ ' is deprecated, please use ', 'Normal' },
{ 'opts.bar.update_debounce', 'WarningMsg' },
{ ' instead', 'Normal' },
}, true, {})
new_opts.general.update_debounce = new_opts.general.update_interval
new_opts.general.update_interval = nil
end
if new_opts.general then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.general', 'WarningMsg' },
{ ' is deprecated, its config fields have been moved to ', 'Normal' },
{ 'opts.bar', 'WarningMsg' },
}, true, {})
new_opts.bar =
vim.tbl_deep_extend('force', new_opts.bar or {}, new_opts.general)
new_opts.general = nil ---@diagnostic disable-line: inject-field
end
if (((new_opts or {}).icons or {}).kinds or {}).use_devicons ~= nil then
vim.api.nvim_echo({
{ '[dropbar.nvim] ', 'Normal' },
{ 'opts.icons.kinds.use_devicons', 'WarningMsg' },
{ ' is deprecated, please use ', 'Normal' },
{ 'opts.icons.kinds.file_icon', 'WarningMsg' },
{ ' and ', 'Normal' },
{ 'opts.icons.kinds.folder_icon', 'WarningMsg' },
{ ' to customize file or directory icons', 'Normal' },
}, true, {})
new_opts.icons.kinds.use_devicons = nil
end
if new_opts.icons and new_opts.icons.enable == false then
local blank_icons = setmetatable({}, {
__index = function()
return ' '
end,
})
M.opts.icons.kinds.dir_icon = ''
M.opts.icons.kinds.file_icon = ''
M.opts.icons.kinds.symbols = blank_icons
M.opts.icons.ui.bar = blank_icons
M.opts.icons.ui.menu = blank_icons
end
M.opts = vim.tbl_deep_extend('force', M.opts, new_opts)
end
---Evaluate a dynamic option value (with type T|fun(...): T)
---@generic T
---@param opt? `T`|fun(...): `T`
---@return `T`?
function M.eval(opt, ...)
if opt and vim.is_callable(opt) then
return opt(...)
end
return opt
end
return M