-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/helpers: refactor mkPlugin helpers
- Loading branch information
1 parent
1391a64
commit e136967
Showing
7 changed files
with
318 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
lib, | ||
nixvimOptions, | ||
nixvimUtils, | ||
toLuaObject, | ||
... | ||
}: | ||
let | ||
mkPlugin = import ./mk-plugin.nix { inherit lib nixvimOptions nixvimUtils; }; | ||
in | ||
rec { | ||
plugins = { | ||
inherit mkPlugin; | ||
inherit (neovim-plugin) mkNeovimPlugin; | ||
inherit (vim-plugin) mkVimPlugin; | ||
}; | ||
|
||
neovim-plugin = import ./neovim-plugin.nix { | ||
inherit | ||
lib | ||
nixvimOptions | ||
nixvimUtils | ||
toLuaObject | ||
mkPlugin | ||
; | ||
}; | ||
|
||
vim-plugin = import ./vim-plugin.nix { | ||
inherit | ||
lib | ||
nixvimOptions | ||
nixvimUtils | ||
mkPlugin | ||
; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
lib, | ||
nixvimOptions, | ||
nixvimUtils, | ||
}: | ||
with lib; | ||
config: | ||
{ | ||
name, | ||
maintainers, | ||
url ? defaultPackage.meta.homepage, | ||
imports ? [ ], | ||
description ? null, | ||
# deprecations | ||
optionsRenamedToSettings ? [ ], | ||
# colorscheme | ||
isColorscheme ? false, | ||
colorscheme ? name, | ||
# options | ||
originalName ? name, | ||
defaultPackage ? null, | ||
extraOptions ? { }, | ||
# config | ||
extraConfig ? cfg: { }, | ||
extraPlugins ? [ ], | ||
extraPackages ? [ ], | ||
}: | ||
let | ||
namespace = if isColorscheme then "colorschemes" else "plugins"; | ||
|
||
optionsRenamedToSettingsWarnings = | ||
let | ||
basePluginPath = [ | ||
namespace | ||
name | ||
]; | ||
settingsPath = basePluginPath ++ [ "settings" ]; | ||
in | ||
map ( | ||
option: | ||
let | ||
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list) | ||
|
||
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath; | ||
in | ||
mkRenamedOptionModule ( | ||
[ | ||
namespace | ||
name | ||
] | ||
++ optionPath | ||
) (settingsPath ++ optionPathSnakeCase) | ||
) optionsRenamedToSettings; | ||
in | ||
{ | ||
meta = { | ||
inherit maintainers; | ||
nixvimInfo = { | ||
inherit description url; | ||
path = [ | ||
namespace | ||
name | ||
]; | ||
}; | ||
}; | ||
|
||
imports = optionsRenamedToSettingsWarnings ++ imports; | ||
|
||
options.${namespace}.${name} = | ||
{ | ||
enable = mkEnableOption originalName; | ||
} | ||
// (optionalAttrs (defaultPackage != null) { | ||
package = nixvimOptions.mkPluginPackageOption originalName defaultPackage; | ||
}) | ||
// extraOptions; | ||
|
||
config = | ||
let | ||
cfg = config.${namespace}.${name}; | ||
in | ||
mkIf cfg.enable (mkMerge [ | ||
{ | ||
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package; | ||
inherit extraPackages; | ||
} | ||
(extraConfig cfg) | ||
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; }) | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
lib, | ||
nixvimOptions, | ||
toLuaObject, | ||
nixvimUtils, | ||
mkPlugin, | ||
}: | ||
with lib; | ||
{ | ||
# TODO: DEPRECATED: use the `settings` option instead | ||
extraOptionsOptions = { | ||
extraOptions = mkOption { | ||
default = { }; | ||
type = with types; attrsOf anything; | ||
description = '' | ||
These attributes will be added to the table parameter for the setup function. | ||
Typically, it can override NixVim's default settings. | ||
''; | ||
}; | ||
}; | ||
|
||
mkNeovimPlugin = | ||
config: | ||
{ | ||
name, | ||
defaultPackage, # make this parameter mandatory for neovim plugins | ||
# deprecations | ||
deprecateExtraOptions ? false, | ||
# colorscheme | ||
isColorscheme ? false, | ||
# options | ||
settingsOptions ? { }, | ||
settingsExample ? null, | ||
settingsDescription ? "Options provided to the `require('${luaName}')${setup}` function.", | ||
hasSettings ? true, | ||
extraOptions ? { }, | ||
# config | ||
setup ? ".setup", | ||
luaName ? name, | ||
callSetup ? true, | ||
... | ||
}@args: | ||
mkPlugin config ( | ||
(removeAttrs args [ | ||
"callSetup" | ||
"deprecateExtraOptions" | ||
"extraConfig" | ||
"extraOptions" | ||
"hasSettings" | ||
"imports" | ||
"luaName" | ||
"settingsExample" | ||
"settingsOptions" | ||
]) | ||
// { | ||
imports = | ||
let | ||
basePluginPath = [ | ||
(if isColorscheme then "colorschemes" else "plugins") | ||
name | ||
]; | ||
settingsPath = basePluginPath ++ [ "settings" ]; | ||
in | ||
(args.imports or [ ]) | ||
++ (optional deprecateExtraOptions ( | ||
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath | ||
)); | ||
|
||
extraOptions = | ||
(optionalAttrs hasSettings { | ||
settings = nixvimOptions.mkSettingsOption { | ||
description = settingsDescription; | ||
options = settingsOptions; | ||
example = settingsExample; | ||
}; | ||
}) | ||
// extraOptions; | ||
|
||
extraConfig = | ||
let | ||
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua"; | ||
in | ||
cfg: | ||
mkMerge ( | ||
[ | ||
{ | ||
${extraConfigNamespace} = optionalString callSetup '' | ||
require('${luaName}')${setup}(${optionalString (cfg ? settings) (toLuaObject cfg.settings)}) | ||
''; | ||
} | ||
] | ||
++ (optional (args ? extraConfig) (args.extraConfig cfg)) | ||
); | ||
} | ||
); | ||
} |
Oops, something went wrong.