-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
rainbow-delimiters.nix
152 lines (139 loc) · 4.55 KB
/
rainbow-delimiters.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
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
{
options.plugins.rainbow-delimiters = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "rainbow-delimiters.nvim";
package = helpers.mkPluginPackageOption "rainbow-delimiters.nvim" pkgs.vimPlugins.rainbow-delimiters-nvim;
strategy = helpers.defaultNullOpts.mkAttrsOf' {
type = types.enum [
"global"
"local"
"noop"
];
pluginDefault = {
default = "global";
};
description = ''
Attrs mapping Tree-sitter language names to strategies.
See `|rb-delimiters-strategy|` for more information about strategies.
'';
example = literalMD ''
```nix
{
# Use global strategy by default
default = "global";
# Use local for HTML
html = "local";
# Pick the strategy for LaTeX dynamically based on the buffer size
latex.__raw = '''
function()
-- Disabled for very large files, global strategy for large files,
-- local strategy otherwise
if vim.fn.line('$') > 10000 then
return nil
elseif vim.fn.line('$') > 1000 then
return require 'rainbow-delimiters'.strategy['global']
end
return require 'rainbow-delimiters'.strategy['local']
end
''';
}
```
'';
};
query =
helpers.defaultNullOpts.mkAttrsOf types.str
{
default = "rainbow-delimiters";
lua = "rainbow-blocks";
}
''
Attrs mapping Tree-sitter language names to queries.
See `|rb-delimiters-query|` for more information about queries.
'';
highlight =
helpers.defaultNullOpts.mkListOf types.str
[
"RainbowDelimiterRed"
"RainbowDelimiterYellow"
"RainbowDelimiterBlue"
"RainbowDelimiterOrange"
"RainbowDelimiterGreen"
"RainbowDelimiterViolet"
"RainbowDelimiterCyan"
]
''
List of names of the highlight groups to use for highlighting, for more information see
`|rb-delimiters-colors|`.
'';
whitelist = helpers.mkNullOrOption (with types; listOf str) ''
List of Tree-sitter languages for which to enable rainbow delimiters.
Rainbow delimiters will be disabled for all other languages.
'';
blacklist = helpers.mkNullOrOption (with types; listOf str) ''
List of Tree-sitter languages for which to disable rainbow delimiters.
Rainbow delimiters will be enabled for all other languages.
'';
log = {
file =
helpers.defaultNullOpts.mkStr { __raw = "vim.fn.stdpath('log') .. '/rainbow-delimiters.log'"; }
''
Path to the log file, default is `rainbow-delimiters.log` in your standard log path
(see `|standard-path|`).
'';
level = helpers.defaultNullOpts.mkLogLevel "warn" ''
Only messages equal to or above this value will be logged.
The default is to log warnings or above.
See `|log_levels|` for possible values.
'';
};
};
config =
let
cfg = config.plugins.rainbow-delimiters;
in
mkIf cfg.enable {
warnings = optional (
!config.plugins.treesitter.enable
) "Nixvim: treesitter-rainbow needs treesitter to function as intended";
assertions = [
{
assertion = (cfg.whitelist == null) || (cfg.blacklist == null);
message = ''
Both `rainbow-delimiters.whitelist` and `rainbow-delimiters.blacklist` should not be
set simultaneously.
Please remove one of them.
'';
}
];
extraPlugins = [ cfg.package ];
globals.rainbow_delimiters =
with cfg;
{
strategy = helpers.ifNonNull' strategy (
mapAttrs' (name: value: {
name = if name == "default" then "__emptyString" else name;
value =
if isString value then helpers.mkRaw "require 'rainbow-delimiters'.strategy['${value}']" else value;
}) strategy
);
query = helpers.ifNonNull' query (
mapAttrs' (name: value: {
name = if name == "default" then "__emptyString" else name;
inherit value;
}) query
);
inherit highlight whitelist blacklist;
log = with log; {
inherit file level;
};
}
// cfg.extraOptions;
};
}