From 6e3a18b86708a10e712e79abb14a33bcda7dc179 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 27 Apr 2024 00:49:30 +0300 Subject: [PATCH] modules/telescope: add option to customize loading --- modules/plugins/navigation/telescope.nix | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/plugins/navigation/telescope.nix b/modules/plugins/navigation/telescope.nix index 4e0f81d..c239844 100644 --- a/modules/plugins/navigation/telescope.nix +++ b/modules/plugins/navigation/telescope.nix @@ -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("")''; }; }; 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); }; }