modules/telescope: add option to customize loading #1

Merged
pleshevskiy merged 1 commit from telescope into main 2024-04-27 01:47:57 +03:00

View file

@ -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);
};
}