Skip to content

Commit 9a156ae

Browse files
committed
plugins/mini-icons: add mockDevIcons
1 parent 84249a9 commit 9a156ae

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

plugins/utils/mini.nix

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
1111
package = "mini-nvim";
1212

1313
extraOptions = {
14+
mockDevIcons = lib.mkEnableOption "mockDevIcons" // {
15+
defaultText = lib.literalMD "`false` **NOTE**: This option is experimental and the default value may change without notice.";
16+
description = ''
17+
Whether to tell `mini.icons` to emulate `nvim-web-devicons` for plugins that don't natively support it.
18+
19+
When enabled, you don't need to set `plugins.web-devicons.enable`. This will replace the need for it.
20+
'';
21+
};
1422
modules = lib.mkOption {
1523
type = with lib.types; attrsOf (attrsOf anything);
1624
default = { };
@@ -82,9 +90,23 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
8290
callSetup = false;
8391
hasSettings = false;
8492
extraConfig = cfg: {
85-
extraConfigLua = lib.foldlAttrs (lines: name: config: ''
86-
${lines}
87-
require(${lib.nixvim.toLuaObject "mini.${name}"}).setup(${lib.nixvim.toLuaObject config})
88-
'') "" cfg.modules;
93+
assertions = [
94+
{
95+
assertion = cfg.mockDevIcons -> cfg.modules ? icons;
96+
message = ''
97+
You have enabled `plugins.mini.mockDevIcons` but have not defined `plugins.mini.modules.icons`.
98+
This setting will have no effect without it.
99+
'';
100+
}
101+
];
102+
extraConfigLua =
103+
lib.foldlAttrs (lines: name: config: ''
104+
${lines}
105+
require(${lib.nixvim.toLuaObject "mini.${name}"}).setup(${lib.nixvim.toLuaObject config})
106+
'') "" cfg.modules
107+
# `MiniIcons` is only in scope if we've called `require('mini.icons')` above
108+
+ lib.optionalString ((cfg.modules ? icons) && cfg.mockDevIcons) ''
109+
MiniIcons.mock_nvim_web_devicons()
110+
'';
89111
};
90112
}

tests/test-sources/plugins/utils/mini.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
background = "#351721";
6060
foreground = "#cdc4c6";
6161
};
62+
icons = { };
6263
indentscope = { };
6364
jump = { };
6465
jump2d = { };
@@ -77,4 +78,12 @@
7778
};
7879
};
7980
};
81+
82+
icons-mock = {
83+
plugins.mini = {
84+
enable = true;
85+
mockDevIcons = true;
86+
modules.icons = { };
87+
};
88+
};
8089
}

0 commit comments

Comments
 (0)