-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
navbuddy.nix
268 lines (226 loc) · 7.59 KB
/
navbuddy.nix
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
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.navbuddy;
percentageType = types.ints.between 0 100;
mkPercentageOpt = default: helpers.defaultNullOpts.mkNullable percentageType (toString default);
in
{
options.plugins.navbuddy = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "nvim-navbuddy";
package = helpers.mkPluginPackageOption "nvim-navbuddy" pkgs.vimPlugins.nvim-navbuddy;
window = {
border = helpers.defaultNullOpts.mkBorder "rounded" "window border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
size = helpers.defaultNullOpts.mkNullable (
with types;
either percentageType (submodule {
options = {
height = mkPercentageOpt 40 "The height size (in %).";
width = mkPercentageOpt 100 "The width size (in %).";
};
})
) 60 "The size of the window.";
position = helpers.defaultNullOpts.mkNullable (
with types;
either percentageType (submodule {
options = {
height = mkPercentageOpt 40 "The height size (in %).";
width = mkPercentageOpt 100 "The width size (in %).";
};
})
) 50 "The position of the window.";
scrolloff = helpers.mkNullOrOption types.int ''
scrolloff value within navbuddy window
'';
sections = {
left = {
size = mkPercentageOpt 20 "The height size (in %).";
border = helpers.defaultNullOpts.mkBorder "rounded" "left section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
};
mid = {
size = mkPercentageOpt 40 "The height size (in %).";
border = helpers.defaultNullOpts.mkBorder "rounded" "mid section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
};
right = {
border = helpers.defaultNullOpts.mkBorder "rounded" "right section border" ''
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
'';
preview =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"leaf"
"always"
"never"
]
''
Right section can show previews too.
Options: "leaf", "always" or "never"
'';
};
};
};
nodeMarkers = {
enabled = helpers.defaultNullOpts.mkBool true "Enable node markers.";
icons = {
leaf = helpers.defaultNullOpts.mkStr " " ''
The icon to use for leaf nodes.
'';
leafSelected = helpers.defaultNullOpts.mkStr " → " ''
The icon to use for selected leaf node.
'';
branch = helpers.defaultNullOpts.mkStr " " ''
The icon to use for branch nodes.
'';
};
};
icons = mapAttrs (name: default: helpers.defaultNullOpts.mkStr default "icon for ${name}.") {
File = " ";
Module = " ";
Namespace = " ";
Package = " ";
Class = " ";
Method = " ";
Property = " ";
Field = " ";
Constructor = " ";
Enum = "";
Interface = "";
Function = " ";
Variable = " ";
Constant = " ";
String = " ";
Number = " ";
Boolean = "◩ ";
Array = " ";
Object = " ";
Key = " ";
Null = " ";
EnumMember = " ";
Struct = " ";
Event = " ";
Operator = " ";
TypeParameter = " ";
};
useDefaultMapping = helpers.defaultNullOpts.mkBool true ''
If set to false, only mappings set by user are set. Else default mappings are used for keys that are not set by user
'';
keymapsSilent = mkOption {
type = types.bool;
description = "Whether navbuddy keymaps should be silent";
default = false;
};
mappings =
helpers.defaultNullOpts.mkAttrsOf types.str
{
"<esc>" = "close";
"q" = "close";
"j" = "next_sibling";
"k" = "previous_sibling";
"h" = "parent";
"l" = "children";
"0" = "root";
"v" = "visual_name";
"V" = "visual_scope";
"y" = "yank_name";
"Y" = "yank_scope";
"i" = "insert_name";
"I" = "insert_scope";
"a" = "append_name";
"A" = "append_scope";
"r" = "rename";
"d" = "delete";
"f" = "fold_create";
"F" = "fold_delete";
"c" = "comment";
"<enter>" = "select";
"o" = "select";
"J" = "move_down";
"K" = "move_up";
"s" = "toggle_preview";
"<C-v>" = "vsplit";
"<C-s>" = "hsplit";
}
''
Actions to be triggered for specified keybindings. It can take either action name i.e `toggle_preview`
Or it can a `rawLua`.
'';
lsp = {
autoAttach = helpers.defaultNullOpts.mkBool false ''
If set to true, you don't need to manually use attach function
'';
preference = helpers.mkNullOrOption (with types; listOf str) ''
list of lsp server names in order of preference
'';
};
sourceBuffer = {
followNode = helpers.defaultNullOpts.mkBool true "Keep the current node in focus on the source buffer";
highlight = helpers.defaultNullOpts.mkBool true "Highlight the currently focused node";
reorient =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"smart"
"top"
"mid"
"none"
]
''
Right section can show previews too.
Options: "leaf", "always" or "never"
'';
scrolloff = helpers.defaultNullOpts.mkInt null ''
scrolloff value when navbuddy is open.
'';
};
};
config =
let
setupOptions =
with cfg;
{
inherit window;
node_markers = with nodeMarkers; {
inherit enabled;
icons = with icons; {
inherit leaf branch;
leaf_selected = leafSelected;
};
};
inherit icons;
use_default_mapping = useDefaultMapping;
lsp = with lsp; {
auto_attach = autoAttach;
inherit preference;
};
source_buffer = sourceBuffer;
mappings = helpers.ifNonNull' cfg.mappings (
mapAttrs (
key: action: if isString action then helpers.mkRaw "actions.${action}()" else action
) mappings
);
}
// cfg.extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua = ''
local actions = require("nvim-navbuddy.actions")
require('nvim-navbuddy').setup(${helpers.toLuaObject setupOptions})
'';
};
}