modules/telescope: add option to customize loading
This commit is contained in:
parent
f21c145f95
commit
6e3a18b867
1 changed files with 13 additions and 11 deletions
|
@ -14,32 +14,34 @@ let
|
|||
if isFunction cfg.extensions then cfg.extensions telescopeExtensions
|
||||
else cfg.extensions;
|
||||
|
||||
extensionOpts = { name, config, ... }: {
|
||||
extensionOpts = { name, ... } @ sub: {
|
||||
options = with lib; with types; {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
description = "Extension name";
|
||||
};
|
||||
|
||||
package = mkPackageOption telescopeExtensions name { };
|
||||
|
||||
settings = mkOption {
|
||||
type = attrs;
|
||||
default = { };
|
||||
description = "Additional configuration to setup an extension";
|
||||
};
|
||||
|
||||
# TODO: add an option to change the way the extension is loaded.
|
||||
|
||||
afterTelescopeSetup = mkOption {
|
||||
type = listOf attrs;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
loadExtension = mkOption {
|
||||
type = nullOr attrs;
|
||||
description = "Expression to load extension";
|
||||
defaultText = literalExpression ''require("telescope").load_extension("<name>")'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
name = lib.mkDefault name;
|
||||
|
||||
afterTelescopeSetup = with nix2lua; lib.optional (config.settings != { })
|
||||
(pipe1 (var config.plugin.telescope-nvim.varName) (call "load_extension" config.name));
|
||||
loadExtension = with nix2lua; lib.mkDefault (pipe1
|
||||
(var config.plugin.telescope-nvim.varName)
|
||||
(call "load_extension" sub.config.name)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -93,7 +95,7 @@ in
|
|||
(lib.filterAttrs (k: v: v.settings != { }) extensions)
|
||||
)
|
||||
]);
|
||||
afterSetup = lib.flatten (map (ext: ext.afterTelescopeSetup) (attrValues extensions));
|
||||
afterSetup = map (ext: ext.loadExtension) (attrValues extensions);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue