-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/telescope: refactor
mkExtension
Allow importing `mkExtension` without needing to supply any dependencies. All dependencies can be accessed via module args anyway.
- Loading branch information
1 parent
c674f10
commit 929bb0c
Showing
11 changed files
with
115 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
name, | ||
package, | ||
extensionName ? name, | ||
settingsOptions ? { }, | ||
settingsExample ? null, | ||
extraOptions ? { }, | ||
imports ? [ ], | ||
optionsRenamedToSettings ? [ ], | ||
extraConfig ? cfg: { }, | ||
}: | ||
let | ||
getPluginAttr = attrs: attrs.plugins.telescope.extensions.${name}; | ||
|
||
renameModule = | ||
{ lib, ... }: | ||
{ | ||
# TODO remove this once all deprecation warnings will have been removed. | ||
imports = | ||
let | ||
basePluginPath = [ | ||
"plugins" | ||
"telescope" | ||
"extensions" | ||
name | ||
]; | ||
settingsPath = basePluginPath ++ [ "settings" ]; | ||
in | ||
builtins.map ( | ||
option: | ||
let | ||
optionPath = lib.toList option; | ||
optionPathSnakeCase = map lib.nixvim.toSnakeCase optionPath; | ||
in | ||
lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase) | ||
) optionsRenamedToSettings; | ||
}; | ||
|
||
module = | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = getPluginAttr config; | ||
in | ||
{ | ||
options.plugins.telescope.extensions.${name} = { | ||
enable = lib.mkEnableOption "the `${name}` telescope extension"; | ||
|
||
package = lib.mkPackageOption pkgs name { | ||
default = [ | ||
"vimPlugins" | ||
package | ||
]; | ||
}; | ||
|
||
settings = lib.nixvim.mkSettingsOption { | ||
description = "settings for the `${name}` telescope extension."; | ||
options = settingsOptions; | ||
example = settingsExample; | ||
}; | ||
} // extraOptions; | ||
|
||
config = lib.mkIf cfg.enable { | ||
extraPlugins = [ cfg.package ]; | ||
|
||
plugins.telescope = { | ||
enabledExtensions = [ extensionName ]; | ||
settings.extensions.${extensionName} = cfg.settings; | ||
}; | ||
}; | ||
}; | ||
|
||
extraConfigModule = { config, ... }: extraConfig (getPluginAttr config); | ||
in | ||
{ | ||
imports = imports ++ [ | ||
module | ||
extraConfigModule | ||
renameModule | ||
]; | ||
} |
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
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