plugins/telescope: add support of extensions
This commit is contained in:
parent
bf360c7fbc
commit
1f0c0b5cb0
1 changed files with 84 additions and 10 deletions
|
@ -1,14 +1,57 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{ config, lib, pkgs, nix2lua, ... }:
|
||||
|
||||
let cfg = config.plugins.navigation.telescope; in
|
||||
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, config, ... }: {
|
||||
options = with lib; with types; {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
description = "Extension name";
|
||||
};
|
||||
package = mkPackageOption telescopeExtensions name { };
|
||||
settings = mkOption {
|
||||
type = attrs;
|
||||
default = { };
|
||||
};
|
||||
|
||||
# TODO: add an option to change the way the extension is loaded.
|
||||
|
||||
afterTelescopeSetup = mkOption {
|
||||
type = listOf attrs;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
name = lib.mkDefault name;
|
||||
|
||||
afterTelescopeSetup = with nix2lua; lib.optional (config.settings != { })
|
||||
(pipe1 (var config.plugin.telescope-nvim.varName) (call "load_extension" config.name));
|
||||
};
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
options.plugins.navigation.telescope = with lib; {
|
||||
options.plugins.navigation.telescope = with lib; with types; {
|
||||
enable = mkEnableOption "telescope";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "telescope-nvim" { };
|
||||
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
type = attrs;
|
||||
default = { };
|
||||
description = ''
|
||||
See: https://github.com/nvim-telescope/telescope.nvim?tab=readme-ov-file#customization
|
||||
|
@ -21,15 +64,46 @@ let cfg = config.plugins.navigation.telescope; in
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
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"; };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
plugin.plenary-nvim = lib.mkDefault { isDependency = true; };
|
||||
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
|
||||
|
||||
plugin.telescope-nvim = {
|
||||
name = "telescope";
|
||||
package = cfg.package;
|
||||
setupSettings = cfg.settings;
|
||||
};
|
||||
(lib.mapAttrsToList
|
||||
(k: v: { extensions."${v.name}" = v.settings; })
|
||||
(lib.filterAttrs (k: v: v.settings != { }) extensions)
|
||||
)
|
||||
]);
|
||||
afterSetup = lib.flatten (map (ext: ext.afterTelescopeSetup) (attrValues extensions));
|
||||
};
|
||||
}
|
||||
|
||||
# extensions
|
||||
(lib.flip lib.mapAttrsToList extensions (packageName: package: {
|
||||
"${packageName}" = {
|
||||
inherit package;
|
||||
isDependency = lib.mkDefault true;
|
||||
};
|
||||
}))
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue