2024-04-30 00:48:10 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
2024-04-26 02:08:23 +03:00
|
|
|
|
2024-04-26 16:33:54 +03:00
|
|
|
let
|
|
|
|
inherit (builtins) match isFunction attrValues;
|
2024-05-09 02:28:24 +03:00
|
|
|
inherit (lib.nix2lua) pipe1 var call;
|
2024-04-26 16:33:54 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-04-27 00:49:30 +03:00
|
|
|
extensionOpts = { name, ... } @ sub: {
|
2024-04-26 16:33:54 +03:00
|
|
|
options = with lib; with types; {
|
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Extension name";
|
|
|
|
};
|
2024-04-27 00:49:30 +03:00
|
|
|
|
2024-04-26 16:33:54 +03:00
|
|
|
package = mkPackageOption telescopeExtensions name { };
|
2024-04-27 00:49:30 +03:00
|
|
|
|
2024-04-26 16:33:54 +03:00
|
|
|
settings = mkOption {
|
|
|
|
type = attrs;
|
|
|
|
default = { };
|
2024-04-27 00:49:30 +03:00
|
|
|
description = "Additional configuration to setup an extension";
|
2024-04-26 16:33:54 +03:00
|
|
|
};
|
|
|
|
|
2024-04-27 00:49:30 +03:00
|
|
|
loadExtension = mkOption {
|
|
|
|
type = nullOr attrs;
|
|
|
|
description = "Expression to load extension";
|
|
|
|
defaultText = literalExpression ''require("telescope").load_extension("<name>")'';
|
2024-04-26 16:33:54 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
name = lib.mkDefault name;
|
2024-05-09 02:28:24 +03:00
|
|
|
loadExtension = lib.mkDefault (pipe1
|
2024-05-10 01:31:47 +03:00
|
|
|
config.plugin.telescope-nvim.var
|
2024-04-27 00:49:30 +03:00
|
|
|
(call "load_extension" sub.config.name)
|
|
|
|
);
|
2024-04-26 16:33:54 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
2024-04-26 02:08:23 +03:00
|
|
|
{
|
2024-04-26 16:33:54 +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 {
|
2024-04-26 16:33:54 +03:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-04-26 16:33:54 +03:00
|
|
|
|
|
|
|
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 {
|
2024-04-26 16:33:54 +03:00
|
|
|
plugin = lib.mkMerge (lib.flatten [
|
|
|
|
{
|
2024-05-10 01:31:47 +03:00
|
|
|
plenary-nvim = { };
|
|
|
|
telescope-nvim = rec {
|
2024-04-26 16:33:54 +03:00
|
|
|
name = "telescope";
|
2024-05-10 01:31:47 +03:00
|
|
|
varName = name;
|
2024-04-26 16:33:54 +03:00
|
|
|
package = cfg.package;
|
|
|
|
setupSettings = lib.mkMerge (lib.flatten [
|
|
|
|
cfg.settings
|
2024-04-26 02:08:23 +03:00
|
|
|
|
2024-04-26 16:33:54 +03:00
|
|
|
(lib.mapAttrsToList
|
|
|
|
(k: v: { extensions."${v.name}" = v.settings; })
|
|
|
|
(lib.filterAttrs (k: v: v.settings != { }) extensions)
|
|
|
|
)
|
|
|
|
]);
|
2024-04-27 00:49:30 +03:00
|
|
|
afterSetup = map (ext: ext.loadExtension) (attrValues extensions);
|
2024-04-26 16:33:54 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# extensions
|
2024-04-27 01:32:49 +03:00
|
|
|
(lib.flip lib.mapAttrsToList extensions (packageName: ext: {
|
2024-05-10 01:31:47 +03:00
|
|
|
"${packageName}" = { inherit (ext) package; };
|
2024-04-26 16:33:54 +03:00
|
|
|
}))
|
|
|
|
]);
|
2024-04-26 02:08:23 +03:00
|
|
|
};
|
|
|
|
}
|