1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-08 11:36:07 +01:00

plugins/rainbow-delimiters: migrate to mkNeovimPlugin

Signed-off-by: saygo-png <saygo.mail@proton.me>
This commit is contained in:
saygo-png 2025-10-01 09:40:46 +02:00 committed by Matt Sturgeon
parent aa47ed384a
commit 61f1475f7f
3 changed files with 156 additions and 147 deletions

View file

@ -1,24 +1,30 @@
{ {
lib, lib,
helpers,
config, config,
pkgs, options,
... ...
}: }:
with lib; let
{ opts = options.plugins.rainbow-delimiters;
options.plugins.rainbow-delimiters = lib.nixvim.plugins.neovim.extraOptionsOptions // { inherit (builtins) any isNull;
enable = mkEnableOption "rainbow-delimiters.nvim"; inherit (lib) mapAttrs' nameValuePair isString;
inherit (lib.nixvim) mkRaw toLuaObject nestedLiteralLua;
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "rainbow-delimiters";
package = "rainbow-delimiters-nvim";
description = "Rainbow delimiters for Neovim with Tree-sitter";
maintainers = [ ];
package = lib.mkPackageOption pkgs "rainbow-delimiters.nvim" { # This plugin uses globals for configuration.
default = [ callSetup = false;
"vimPlugins"
"rainbow-delimiters-nvim"
];
};
strategy = helpers.defaultNullOpts.mkAttrsOf' { # TODO: introduced 2025-10-1: remove after 26.05
type = types.enum [ inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings imports;
extraOptions = {
strategy = lib.nixvim.defaultNullOpts.mkAttrsOf' {
type = lib.types.enum [
"global" "global"
"local" "local"
"noop" "noop"
@ -29,12 +35,13 @@ with lib;
description = '' description = ''
Attrs mapping Tree-sitter language names to strategies. Attrs mapping Tree-sitter language names to strategies.
See `|rb-delimiters-strategy|` for more information about strategies. See `|rb-delimiters-strategy|` for more information about strategies.
This option adds definitions to `${opts.settings}.strategy` wrapped with required Lua code.
''; '';
example = literalMD '' example = lib.literalMD ''
```nix ```nix
{ {
# Use global strategy by default # Use global strategy by default
default = "global"; "" = "global";
# Use local for HTML # Use local for HTML
html = "local"; html = "local";
@ -56,102 +63,66 @@ with lib;
``` ```
''; '';
}; };
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 = settingsExample = {
let blacklist = [ "json" ];
cfg = config.plugins.rainbow-delimiters; strategy = {
in "" = nestedLiteralLua "require 'rainbow-delimiters'.strategy['global']";
mkIf cfg.enable { "nix" = nestedLiteralLua "require 'rainbow-delimiters'.strategy['local']";
warnings = lib.nixvim.mkWarnings "plugins.rainbow-delimiters" { };
highlight = [
"RainbowDelimiterViolet"
"RainbowDelimiterBlue"
"RainbowDelimiterGreen"
];
};
extraConfig = cfg: {
warnings = lib.nixvim.mkWarnings "plugins.rainbow-delimiters" [
{
when = !config.plugins.treesitter.enable; when = !config.plugins.treesitter.enable;
message = "This plugin needs treesitter to function as intended."; message = "This plugin needs treesitter to function as intended.";
}; }
assertions = lib.nixvim.mkAssertions "plugins.rainbow-delimiters" {
assertion = (cfg.whitelist == null) || (cfg.blacklist == null);
# TODO: introduced 2025-10-1: remove after 26.05
{
when = cfg.strategy ? default;
message = '' message = ''
Both `rainbow-delimiters.whitelist` and `rainbow-delimiters.blacklist` should not be Setting `${opts.strategy}` keys to the string `"default"` is deprecated.
set simultaneously. You can set them to an empty string `""` instead.
Please remove one of them.
''; '';
}; }
{
when = (cfg.query ? default) && (cfg.query.default != "_mkMergedOptionModule");
message = ''
Setting `${opts.query}` keys to the string `"default"` is deprecated.
You can set them to an empty string `""` instead.
'';
}
];
extraPlugins = [ cfg.package ]; assertions = lib.nixvim.mkAssertions "plugins.rainbow-delimiters" {
assertion = any isNull [
globals.rainbow_delimiters = (cfg.settings.whitelist or null)
with cfg; (cfg.settings.blacklist or null)
{ ];
strategy = helpers.ifNonNull' strategy ( message = ''
mapAttrs' (name: value: { Both `${opts.settings}.whitelist` and `${opts.settings}.blacklist` should not be set simultaneously.
name = if name == "default" then "__emptyString" else name; Please remove one of them.
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;
}; };
globals.rainbow_delimiters = lib.mkMerge [
cfg.settings
(lib.mkIf (cfg.strategy != null) {
strategy = mapAttrs' (
n: v:
nameValuePair (if n == "default" then "" else n) (
if isString v then mkRaw "require('rainbow-delimiters').strategy[${toLuaObject v}]" else v
)
) cfg.strategy;
})
];
};
} }

View file

@ -0,0 +1,40 @@
lib:
let
inherit (lib) mapAttrs' nameValuePair;
inherit (lib.nixvim) ifNonNull';
basePathAnd = lib.concat [
"plugins"
"rainbow-delimiters"
];
in
{
deprecateExtraOptions = true;
optionsRenamedToSettings = map (lib.splitString ".") [
"highlight"
"whitelist"
"blacklist"
"log.file"
"log.level"
];
imports = [
(
let
oldOptPath = basePathAnd [ "query" ];
in
lib.mkChangedOptionModule oldOptPath
(basePathAnd [
"settings"
"query"
])
(
config:
let
old = lib.getAttrFromPath oldOptPath config;
in
ifNonNull' old (mapAttrs' (n: nameValuePair (if n == "default" then "" else n)) old)
)
)
];
}

View file

@ -11,58 +11,56 @@
treesitter.enable = true; treesitter.enable = true;
rainbow-delimiters = { rainbow-delimiters = {
enable = true; enable = true;
settings = {
strategy = { settingsExample = {
default = "global"; blacklist = [ "json" ];
html = "local"; strategy = {
latex.__raw = '' "".__raw = "require 'rainbow-delimiters'.strategy['global']";
function() "nix".__raw = "require 'rainbow-delimiters'.strategy['local']";
-- Disabled for very large files, global strategy for large files, };
-- local strategy otherwise highlight = [
if vim.fn.line('$') > 10000 then "RainbowDelimiterViolet"
return nil "RainbowDelimiterBlue"
elseif vim.fn.line('$') > 1000 then "RainbowDelimiterGreen"
return rainbow.strategy['global'] ];
end };
return rainbow.strategy['local']
end
'';
};
query = {
default = "rainbow-delimiters";
lua = "rainbow-blocks";
};
highlight = [
"RainbowDelimiterRed"
"RainbowDelimiterYellow"
"RainbowDelimiterBlue"
"RainbowDelimiterOrange"
"RainbowDelimiterGreen"
"RainbowDelimiterViolet"
"RainbowDelimiterCyan"
];
blacklist = [
"c"
"cpp"
];
log = {
file.__raw = "vim.fn.stdpath('log') .. '/rainbow-delimiters.log'";
level = "warn";
}; };
}; };
}; };
}; };
example-whitelist = { defaults = {
plugins = { plugins = {
treesitter.enable = true; treesitter.enable = true;
rainbow-delimiters = { rainbow-delimiters = {
enable = true; enable = true;
settings = {
query = {
"" = "rainbow-delimiters";
javascript = "rainbow-delimiters-react";
};
strategy = {
"".__raw = "require 'rainbow-delimiters'.strategy['global']";
};
priority = {
"".__raw =
"math.floor(((vim.hl or vim.highlight).priorities.semantic_tokens + (vim.hl or vim.highlight).priorities.treesitter) / 2)";
};
log = {
level.__raw = "vim.log.levels.WARN";
file.__raw = "vim.fn.stdpath('log') .. '/rainbow-delimiters.log'";
};
highlight = [
"RainbowDelimiterRed"
"RainbowDelimiterYellow"
"RainbowDelimiterBlue"
"RainbowDelimiterOrange"
"RainbowDelimiterGreen"
"RainbowDelimiterViolet"
"RainbowDelimiterCyan"
];
whitelist = [ };
"c"
"cpp"
];
}; };
}; };
}; };