Skip to content

Commit

Permalink
lib/neovim-plugin: lazy prefer opts over config
Browse files Browse the repository at this point in the history
Upstream documentation recommends just providing the opts instead of the
function call explicitly.
  • Loading branch information
khaneliman committed Dec 10, 2024
1 parent 06a4828 commit 93c89bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
9 changes: 3 additions & 6 deletions lib/neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@
name = originalName;
main = luaName;
pkg = cfg.package;
# Use provided config, otherwise fallback to normal lua content
config =
cfg.lazyLoad.settings.config or
# We need to wrap it in a function so it doesn't execute immediately
("function()\n " + cfg.luaConfig.content + " \nend");
# Use provided opts, otherwise fallback to settings
opts = cfg.lazyLoad.settings.opts or cfg.settings;
}
// (lib.removeAttrs cfg.lazyLoad.settings [
"config"
"opts"
])
)
];
Expand Down
38 changes: 2 additions & 36 deletions tests/test-sources/plugins/lazyloading/lazy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
plugins = config.plugins.lazy.plugins or [ ];
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
in
plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.config.__raw;
message = "`lazy.plugins[0].after` should have contained `neotest` lua content.";
plugin != null && config.plugins.neotest.settings == plugin.opts;
message = "`lazy.plugins[0].opts` should have contained `neotest` settings.";
}
];
};
Expand Down Expand Up @@ -102,38 +102,4 @@
}
];
};
wrap-functionless-luaConfig =
{ config, ... }:
{
plugins = {
lazy = {
enable = true;
};
web-devicons.enable = false;
telescope = {
enable = true;
lazyLoad = {
enable = true;
settings = {
cmd = [ "Telescope" ];
};
};
};
};

assertions = [
{
assertion = (builtins.length config.plugins.lazy.plugins) == 1;
message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lazy.plugins;
in
plugin.config.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend";
message = "`lazy.plugins[0].config` should have contained a function wrapped `telescope` lua content.";
}
];
};
}

0 comments on commit 93c89bb

Please sign in to comment.