2023-08-25 14:09:41 +02:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
2023-08-25 14:09:41 +02:00
|
|
|
config,
|
2023-11-06 15:04:08 +01:00
|
|
|
pkgs,
|
2023-08-25 14:09:41 +02:00
|
|
|
...
|
|
|
|
}:
|
2023-11-06 15:04:08 +01:00
|
|
|
with lib; {
|
2023-08-25 14:09:41 +02:00
|
|
|
options.plugins.rainbow-delimiters =
|
|
|
|
helpers.extraOptionsOptions
|
|
|
|
// {
|
|
|
|
enable = mkEnableOption "rainbow-delimiters.nvim";
|
|
|
|
|
|
|
|
package =
|
|
|
|
helpers.mkPackageOption
|
|
|
|
"rainbow-delimiters.nvim"
|
|
|
|
pkgs.vimPlugins.rainbow-delimiters-nvim;
|
|
|
|
|
|
|
|
strategy =
|
|
|
|
helpers.defaultNullOpts.mkNullable
|
|
|
|
(
|
|
|
|
with types;
|
|
|
|
attrsOf (
|
|
|
|
either
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.nixvimTypes.rawLua
|
2023-08-25 14:09:41 +02:00
|
|
|
(enum ["global" "local" "noop"])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
''
|
|
|
|
{
|
|
|
|
default = "global";
|
|
|
|
}
|
|
|
|
''
|
|
|
|
''
|
|
|
|
Attrs mapping Tree-sitter language names to strategies.
|
|
|
|
See `|rb-delimiters-strategy|` for more information about strategies.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```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.mkNullable
|
|
|
|
(with types; attrsOf 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.mkNullable (with types; listOf 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.mkNullable
|
2024-01-01 23:33:53 +01:00
|
|
|
(with types; either str helpers.nixvimTypes.rawLua)
|
2023-08-25 14:09:41 +02:00
|
|
|
''
|
|
|
|
{
|
|
|
|
__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|`).
|
|
|
|
'';
|
|
|
|
|
2023-11-30 15:50:24 +01:00
|
|
|
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.
|
|
|
|
'';
|
2023-08-25 14:09:41 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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; {
|
2023-11-30 15:50:24 +01:00
|
|
|
inherit
|
|
|
|
file
|
|
|
|
level
|
|
|
|
;
|
2023-08-25 14:09:41 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
// cfg.extraOptions;
|
|
|
|
};
|
|
|
|
}
|