nixeovim/modules/plugins/navigation/telescope.nix

112 lines
2.9 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, nix2lua, ... }:
2024-04-26 02:08:23 +03:00
let
inherit (builtins) match isFunction attrValues;
cfg = config.plugins.navigation.telescope;
telescopeExtensions = lib.flip lib.filterAttrs pkgs.vimPlugins (k: v:
k != "telescope-nvim"
&& match "^.+[-_]telescope$|^telescope[-_].+$" k == [ ]
);
extensions =
if isFunction cfg.extensions then cfg.extensions telescopeExtensions
else cfg.extensions;
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";
};
loadExtension = mkOption {
type = nullOr attrs;
description = "Expression to load extension";
defaultText = literalExpression ''require("telescope").load_extension("<name>")'';
};
};
config = {
name = lib.mkDefault name;
loadExtension = with nix2lua; lib.mkDefault (pipe1
(var config.plugin.telescope-nvim.varName)
(call "load_extension" sub.config.name)
);
};
};
in
2024-04-26 02:08:23 +03:00
{
options.plugins.navigation.telescope = with lib; with types; {
2024-04-26 02:08:23 +03:00
enable = mkEnableOption "telescope";
package = mkPackageOption pkgs.vimPlugins "telescope-nvim" { };
settings = mkOption {
type = attrs;
2024-04-26 02:08:23 +03:00
default = { };
description = ''
See: https://github.com/nvim-telescope/telescope.nvim?tab=readme-ov-file#customization
'';
example = {
pickers = {
find_files = {
theme = "dropdown";
};
};
};
};
extensions = mkOption {
type = let extSubmodule = attrsOf (submodule extensionOpts); in oneOf [
(functionTo (extSubmodule))
extSubmodule
];
default = { };
defaultText = literalExpression "{}";
example = {
telescope-live-grep-args-nvim = { name = "live_grep_args"; };
};
};
2024-04-26 02:08:23 +03:00
};
config = lib.mkIf cfg.enable {
plugin = lib.mkMerge (lib.flatten [
{
plenary-nvim = lib.mkDefault { isDependency = true; };
telescope-nvim = {
name = "telescope";
package = cfg.package;
setupSettings = lib.mkMerge (lib.flatten [
cfg.settings
2024-04-26 02:08:23 +03:00
(lib.mapAttrsToList
(k: v: { extensions."${v.name}" = v.settings; })
(lib.filterAttrs (k: v: v.settings != { }) extensions)
)
]);
afterSetup = map (ext: ext.loadExtension) (attrValues extensions);
};
}
# extensions
2024-04-27 01:32:49 +03:00
(lib.flip lib.mapAttrsToList extensions (packageName: ext: {
"${packageName}" = {
2024-04-27 01:32:49 +03:00
inherit (ext) package;
isDependency = lib.mkDefault true;
};
}))
]);
2024-04-26 02:08:23 +03:00
};
}