forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
helpers: move mkPlugin and mkDefaultOpt to helpers.vim-plugin
- Loading branch information
1 parent
ddce82d
commit 8f90372
Showing
22 changed files
with
450 additions
and
440 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 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 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,104 @@ | ||
{ | ||
lib, | ||
mkPackageOption, | ||
}: | ||
with lib; { | ||
mkPlugin = { | ||
config, | ||
lib, | ||
... | ||
}: { | ||
name, | ||
description ? null, | ||
package ? null, | ||
extraPlugins ? [], | ||
extraPackages ? [], | ||
options ? {}, | ||
globalPrefix ? "", | ||
... | ||
}: let | ||
cfg = config.plugins.${name}; | ||
|
||
# TODO support nested options! | ||
pluginOptions = | ||
mapAttrs | ||
( | ||
optName: opt: | ||
opt.option | ||
) | ||
options; | ||
globals = | ||
mapAttrs' | ||
(optName: opt: { | ||
name = let | ||
optGlobal = | ||
if opt.global == null | ||
then optName | ||
else opt.global; | ||
in | ||
globalPrefix + optGlobal; | ||
value = cfg.${optName}; | ||
}) | ||
options; | ||
# does this evaluate package? | ||
packageOption = | ||
if package == null | ||
then {} | ||
else { | ||
package = mkPackageOption name package; | ||
}; | ||
|
||
extraConfigOption = | ||
if (isString globalPrefix) && (globalPrefix != "") | ||
then { | ||
extraConfig = mkOption { | ||
type = with types; attrsOf anything; | ||
description = '' | ||
The configuration options for ${name} without the '${globalPrefix}' prefix. | ||
Example: To set '${globalPrefix}_foo_bar' to 1, write | ||
```nix | ||
extraConfig = { | ||
foo_bar = true; | ||
}; | ||
``` | ||
''; | ||
default = {}; | ||
}; | ||
} | ||
else {}; | ||
in { | ||
options.plugins.${name} = | ||
{ | ||
enable = mkEnableOption ( | ||
if description == null | ||
then name | ||
else description | ||
); | ||
} | ||
// extraConfigOption | ||
// packageOption | ||
// pluginOptions; | ||
|
||
config = mkIf cfg.enable { | ||
inherit extraPackages globals; | ||
# does this evaluate package? it would not be desired to evaluate pacakge if we use another package. | ||
extraPlugins = extraPlugins ++ optional (package != null) cfg.package; | ||
}; | ||
}; | ||
|
||
mkDefaultOpt = { | ||
type, | ||
global ? null, | ||
description ? null, | ||
example ? null, | ||
default ? null, | ||
... | ||
}: { | ||
option = mkOption { | ||
type = types.nullOr type; | ||
inherit default description example; | ||
}; | ||
|
||
inherit global; | ||
}; | ||
} |
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 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 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 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 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 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 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
Oops, something went wrong.