Skip to content

Commit

Permalink
plugins/lazy.nvim: make pluginType freeform
Browse files Browse the repository at this point in the history
  • Loading branch information
my7h3le committed Aug 25, 2024
1 parent 3b50eae commit 5a142a3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
74 changes: 41 additions & 33 deletions plugins/pluginmanagers/lazy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ in
with types;
let
pluginType = either package (submodule {
freeformType = types.attrsOf types.anything;
options = {
dir = helpers.mkNullOrOption str "A directory pointing to a local plugin";

Expand Down Expand Up @@ -162,40 +163,47 @@ in
plugin:
let
keyExists = keyToCheck: attrSet: lib.elem keyToCheck (lib.attrNames attrSet);
converted =
if isDerivation plugin then
{ dir = "${lazyPath}/${lib.getName plugin}"; }
else
let
handledPluginOptions = {
"__unkeyed" = plugin.name;

inherit (plugin)
cmd
cond
config
dev
enabled
event
ft
init
keys
lazy
main
module
name
optional
opts
priority
submodules
;

dependencies = helpers.ifNonNull' plugin.dependencies (
if isList plugin.dependencies then (pluginListToLua plugin.dependencies) else plugin.dependencies
);

dir =
if plugin ? dir && plugin.dir != null then plugin.dir else "${lazyPath}/${lib.getName plugin.pkg}";
};
freeformPluginOptions = lib.removeAttrs plugin ((lib.attrNames handledPluginOptions) ++ [ "pkg" ]);
combinedPluginOptions = freeformPluginOptions // handledPluginOptions;
in
combinedPluginOptions;
in
if isDerivation plugin then
{ dir = "${lazyPath}/${lib.getName plugin}"; }
else
{
"__unkeyed" = plugin.name;

inherit (plugin)
cmd
cond
config
dev
enabled
event
ft
init
keys
lazy
main
module
name
optional
opts
priority
submodules
;

dependencies = helpers.ifNonNull' plugin.dependencies (
if isList plugin.dependencies then (pluginListToLua plugin.dependencies) else plugin.dependencies
);

dir =
if plugin ? dir && plugin.dir != null then plugin.dir else "${lazyPath}/${lib.getName plugin.pkg}";
};
converted;

pluginListToLua = map pluginToLua;

Expand Down
8 changes: 8 additions & 0 deletions tests/test-sources/plugins/pluginmanagers/lazy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
plugins = [
vim-closer

# Test freeform
{
pkg = vim-dispatch;
# The below is not actually a property in the `lazy.nvim` plugin spec
# but is purely to test freeform capabilities of the `pluginType`.
blah = "test";
}

# Load on specific commands
{
pkg = vim-dispatch;
Expand Down

0 comments on commit 5a142a3

Please sign in to comment.