From 9a156ae60cacce99bdec4d94275f38e7d5ca12fe Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 5 Sep 2024 18:30:03 -0500 Subject: [PATCH] plugins/mini-icons: add mockDevIcons --- plugins/utils/mini.nix | 30 ++++++++++++++++++++--- tests/test-sources/plugins/utils/mini.nix | 9 +++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/plugins/utils/mini.nix b/plugins/utils/mini.nix index 6a3c7daa..713d2241 100644 --- a/plugins/utils/mini.nix +++ b/plugins/utils/mini.nix @@ -11,6 +11,14 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin { package = "mini-nvim"; extraOptions = { + mockDevIcons = lib.mkEnableOption "mockDevIcons" // { + defaultText = lib.literalMD "`false` **NOTE**: This option is experimental and the default value may change without notice."; + description = '' + Whether to tell `mini.icons` to emulate `nvim-web-devicons` for plugins that don't natively support it. + + When enabled, you don't need to set `plugins.web-devicons.enable`. This will replace the need for it. + ''; + }; modules = lib.mkOption { type = with lib.types; attrsOf (attrsOf anything); default = { }; @@ -82,9 +90,23 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin { callSetup = false; hasSettings = false; extraConfig = cfg: { - extraConfigLua = lib.foldlAttrs (lines: name: config: '' - ${lines} - require(${lib.nixvim.toLuaObject "mini.${name}"}).setup(${lib.nixvim.toLuaObject config}) - '') "" cfg.modules; + assertions = [ + { + assertion = cfg.mockDevIcons -> cfg.modules ? icons; + message = '' + You have enabled `plugins.mini.mockDevIcons` but have not defined `plugins.mini.modules.icons`. + This setting will have no effect without it. + ''; + } + ]; + extraConfigLua = + lib.foldlAttrs (lines: name: config: '' + ${lines} + require(${lib.nixvim.toLuaObject "mini.${name}"}).setup(${lib.nixvim.toLuaObject config}) + '') "" cfg.modules + # `MiniIcons` is only in scope if we've called `require('mini.icons')` above + + lib.optionalString ((cfg.modules ? icons) && cfg.mockDevIcons) '' + MiniIcons.mock_nvim_web_devicons() + ''; }; } diff --git a/tests/test-sources/plugins/utils/mini.nix b/tests/test-sources/plugins/utils/mini.nix index b8c80cae..0ad679ac 100644 --- a/tests/test-sources/plugins/utils/mini.nix +++ b/tests/test-sources/plugins/utils/mini.nix @@ -59,6 +59,7 @@ background = "#351721"; foreground = "#cdc4c6"; }; + icons = { }; indentscope = { }; jump = { }; jump2d = { }; @@ -77,4 +78,12 @@ }; }; }; + + icons-mock = { + plugins.mini = { + enable = true; + mockDevIcons = true; + modules.icons = { }; + }; + }; }