modules/telescope: add option to customize loading

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-27 00:49:30 +03:00
parent f21c145f95
commit 6e3a18b867
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2

View file

@ -14,32 +14,34 @@ let
if isFunction cfg.extensions then cfg.extensions telescopeExtensions if isFunction cfg.extensions then cfg.extensions telescopeExtensions
else cfg.extensions; else cfg.extensions;
extensionOpts = { name, config, ... }: { extensionOpts = { name, ... } @ sub: {
options = with lib; with types; { options = with lib; with types; {
name = mkOption { name = mkOption {
type = str; type = str;
description = "Extension name"; description = "Extension name";
}; };
package = mkPackageOption telescopeExtensions name { }; package = mkPackageOption telescopeExtensions name { };
settings = mkOption { settings = mkOption {
type = attrs; type = attrs;
default = { }; default = { };
description = "Additional configuration to setup an extension";
}; };
# TODO: add an option to change the way the extension is loaded. loadExtension = mkOption {
type = nullOr attrs;
afterTelescopeSetup = mkOption { description = "Expression to load extension";
type = listOf attrs; defaultText = literalExpression ''require("telescope").load_extension("<name>")'';
readOnly = true;
internal = true;
}; };
}; };
config = { config = {
name = lib.mkDefault name; name = lib.mkDefault name;
loadExtension = with nix2lua; lib.mkDefault (pipe1
afterTelescopeSetup = with nix2lua; lib.optional (config.settings != { }) (var config.plugin.telescope-nvim.varName)
(pipe1 (var config.plugin.telescope-nvim.varName) (call "load_extension" config.name)); (call "load_extension" sub.config.name)
);
}; };
}; };
@ -93,7 +95,7 @@ in
(lib.filterAttrs (k: v: v.settings != { }) extensions) (lib.filterAttrs (k: v: v.settings != { }) extensions)
) )
]); ]);
afterSetup = lib.flatten (map (ext: ext.afterTelescopeSetup) (attrValues extensions)); afterSetup = map (ext: ext.loadExtension) (attrValues extensions);
}; };
} }