Skip to content

plugins/rainbow: init #3574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions plugins/by-name/rainbow/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ lib, ... }:
lib.nixvim.plugins.mkVimPlugin {
name = "rainbow";
package = "rainbow";
description = "Rainbow parentheses improved — shorter code, no level limit, smooth and fast with powerful configuration.";
maintainers = [ lib.maintainers.saygo-png ];
globalPrefix = "rainbow_";

settingsExample = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave the example test case as is, but settingsExample here is used to generate the documentation. Hence, it would be better to shorten it to 5-10 options, otherwise it becomes quite unreadable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defaults set by the plugin are almost identical to the example i took from the readme. So the default and example test cases almost test the same thing. Should i remove the example test case because of that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferred to have settingsExample and example be more real world configuration examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferred to have settingsExample and example be more real world configuration examples.

I can't really come up with anything more practical here. The issue is that the configuration for this plugin is mostly just colors, the rest is defined by default and works well. Majority of the fancy options are for fixing compatibility with other plugins but I've never had to use them.

Current example does show how you can disable filetypes, basic regex escaping from nix, and configure the colors which id wager is what most people will ever do with this plugin's configuration.

active = 1;
conf = {
guifgs = [
"#7d8618"
"darkorange3"
"seagreen3"
"firebrick"
];
operators = "_,_";
parentheses = [
"start=/(/ end=/)/ fold"
"start=/\\[/ end=/\\]/ fold"
];
separately = {
"*" = { };
markdown = {
parentheses_options = "containedin=markdownCode contained";
};
haskell = {
parentheses = [
"start=/\\[/ end=/\\]/ fold"
"start=/\v\{\ze[^-]/ end=/}/ fold"
];
};
css = 0;
};
};
};
}
112 changes: 112 additions & 0 deletions tests/test-sources/plugins/by-name/rainbow/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
empty = {
plugins.rainbow.enable = true;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a defaults test case that explicitly sets each option to its default value, as documented upstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added what i could, but sadly i just don't have the regex skills to properly escape these complex expressions in nix, in such a way that they also get escaped in lua while preserving their original meaning.
You can see what is missing from the defaults and the regex horror here: https://github.com/luochen1990/rainbow/blob/76ca1a20aa42edb5c65c19029968aad4625790dc/autoload/rainbow_main.vim

defaults = {
plugins.rainbow = {
enable = true;
settings = {
conf = {
guifgs = [
"royalblue3"
"darkorange3"
"seagreen3"
"firebrick"
];
ctermfgs = [
"lightblue"
"lightyellow"
"lightcyan"
"lightmagenta"
];
guis = [ "" ];
cterms = [ "" ];
operators = "_,_";
contains_prefix = "TOP";
parentheses_options = "";
parentheses = [
"start=/(/ end=/)/ fold"
"start=/\\[/ end=/\\]/ fold"
"start=/{/ end=/}/ fold"
];
separately = {
markdown = {
parentheses_options = "containedin=markdownCode contained";
};
lisp = {
guifgs = [
"royalblue3"
"darkorange3"
"seagreen3"
"firebrick"
"darkorchid3"
];
};
haskell = {
parentheses = [
"start=/(/ end=/)/ fold"
"start=/\\[/ end=/\\]/ fold"
"start=/\v\{\ze[^-]/ end=/}/ fold"
];
};
tex = {
parentheses_options = "containedin=texDocZone";
parentheses = [
"start=/(/ end=/)/"
"start=/\\[/ end=/\\]/"
];
};
vim = {
parentheses_options = "containedin=vimFuncBody,vimExecute";
parentheses = [
"start=/(/ end=/)/"
"start=/\\[/ end=/\\]/"
"start=/{/ end=/}/ fold"
];
};
perl = {
syn_name_prefix = "perlBlockFoldRainbow";
};
stylus = {
parentheses = [ "start=/{/ end=/}/ fold contains=@colorableGroup" ];
};
css = 0;
sh = 0;
vimwiki = 0;
};
};
};
};
};

example = {
plugins.rainbow = {
enable = true;
settings = {
active = 1;
conf = {
guifgs = [
"#7d8618"
"darkorange3"
"seagreen3"
"firebrick"
];
parentheses = [
"start=/(/ end=/)/ fold"
"start=/\\[/ end=/\\]/ fold"
];
separately = {
"*" = { };
haskell = {
parentheses = [
"start=/\\[/ end=/\\]/ fold"
"start=/\v\{\ze[^-]/ end=/}/ fold"
];
};
};
};
};
};
};
}