mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
plugins/telescope: refactor mkExtension
Allow importing `mkExtension` without needing to supply any dependencies. All dependencies can be accessed via module args anyway.
This commit is contained in:
parent
c674f10d18
commit
929bb0cd1c
11 changed files with 115 additions and 136 deletions
|
@ -1,85 +1,4 @@
|
||||||
{
|
lib: rec {
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (lib.nixvim) mkSettingsOption toSnakeCase;
|
|
||||||
inherit (lib) mkPackageOption;
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
mkExtension =
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
package,
|
|
||||||
extensionName ? name,
|
|
||||||
settingsOptions ? { },
|
|
||||||
settingsExample ? null,
|
|
||||||
extraOptions ? { },
|
|
||||||
imports ? [ ],
|
|
||||||
optionsRenamedToSettings ? [ ],
|
|
||||||
extraConfig ? cfg: { },
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
# TODO remove this once all deprecation warnings will have been removed.
|
|
||||||
imports =
|
|
||||||
let
|
|
||||||
basePluginPath = [
|
|
||||||
"plugins"
|
|
||||||
"telescope"
|
|
||||||
"extensions"
|
|
||||||
name
|
|
||||||
];
|
|
||||||
settingsPath = basePluginPath ++ [ "settings" ];
|
|
||||||
in
|
|
||||||
imports
|
|
||||||
++ (map (
|
|
||||||
option:
|
|
||||||
let
|
|
||||||
optionPath = lib.toList option;
|
|
||||||
|
|
||||||
optionPathSnakeCase = map toSnakeCase optionPath;
|
|
||||||
in
|
|
||||||
lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
|
||||||
) optionsRenamedToSettings);
|
|
||||||
|
|
||||||
options.plugins.telescope.extensions.${name} = {
|
|
||||||
enable = lib.mkEnableOption "the `${name}` telescope extension";
|
|
||||||
|
|
||||||
package = mkPackageOption pkgs name {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
package
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
settings = mkSettingsOption {
|
|
||||||
description = "settings for the `${name}` telescope extension.";
|
|
||||||
options = settingsOptions;
|
|
||||||
example = settingsExample;
|
|
||||||
};
|
|
||||||
} // extraOptions;
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
cfg = config.plugins.telescope.extensions.${name};
|
|
||||||
in
|
|
||||||
lib.mkIf cfg.enable (
|
|
||||||
lib.mkMerge [
|
|
||||||
{
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
plugins.telescope = {
|
|
||||||
enabledExtensions = [ extensionName ];
|
|
||||||
settings.extensions.${extensionName} = cfg.settings;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
(extraConfig cfg)
|
|
||||||
]
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
# FIXME: don't manually put Default in the description
|
# FIXME: don't manually put Default in the description
|
||||||
# TODO: Comply with #603
|
# TODO: Comply with #603
|
||||||
mkModeMappingsOption =
|
mkModeMappingsOption =
|
||||||
|
|
85
plugins/by-name/telescope/extensions/_mk-extension.nix
Normal file
85
plugins/by-name/telescope/extensions/_mk-extension.nix
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
package,
|
||||||
|
extensionName ? name,
|
||||||
|
settingsOptions ? { },
|
||||||
|
settingsExample ? null,
|
||||||
|
extraOptions ? { },
|
||||||
|
imports ? [ ],
|
||||||
|
optionsRenamedToSettings ? [ ],
|
||||||
|
extraConfig ? cfg: { },
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
getPluginAttr = attrs: attrs.plugins.telescope.extensions.${name};
|
||||||
|
|
||||||
|
renameModule =
|
||||||
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
# TODO remove this once all deprecation warnings will have been removed.
|
||||||
|
imports =
|
||||||
|
let
|
||||||
|
basePluginPath = [
|
||||||
|
"plugins"
|
||||||
|
"telescope"
|
||||||
|
"extensions"
|
||||||
|
name
|
||||||
|
];
|
||||||
|
settingsPath = basePluginPath ++ [ "settings" ];
|
||||||
|
in
|
||||||
|
builtins.map (
|
||||||
|
option:
|
||||||
|
let
|
||||||
|
optionPath = lib.toList option;
|
||||||
|
optionPathSnakeCase = map lib.nixvim.toSnakeCase optionPath;
|
||||||
|
in
|
||||||
|
lib.mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
||||||
|
) optionsRenamedToSettings;
|
||||||
|
};
|
||||||
|
|
||||||
|
module =
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = getPluginAttr config;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.plugins.telescope.extensions.${name} = {
|
||||||
|
enable = lib.mkEnableOption "the `${name}` telescope extension";
|
||||||
|
|
||||||
|
package = lib.mkPackageOption pkgs name {
|
||||||
|
default = [
|
||||||
|
"vimPlugins"
|
||||||
|
package
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = lib.nixvim.mkSettingsOption {
|
||||||
|
description = "settings for the `${name}` telescope extension.";
|
||||||
|
options = settingsOptions;
|
||||||
|
example = settingsExample;
|
||||||
|
};
|
||||||
|
} // extraOptions;
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
extraPlugins = [ cfg.package ];
|
||||||
|
|
||||||
|
plugins.telescope = {
|
||||||
|
enabledExtensions = [ extensionName ];
|
||||||
|
settings.extensions.${extensionName} = cfg.settings;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfigModule = { config, ... }: extraConfig (getPluginAttr config);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports = imports ++ [
|
||||||
|
module
|
||||||
|
extraConfigModule
|
||||||
|
renameModule
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,15 +1,11 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; };
|
inherit (import ./_helpers.nix lib) mkMappingsOption;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
inherit (lib.nixvim) defaultNullOpts mkNullOrStr;
|
inherit (lib.nixvim) defaultNullOpts mkNullOrStr;
|
||||||
in
|
in
|
||||||
telescopeHelpers.mkExtension {
|
mkExtension {
|
||||||
name = "file-browser";
|
name = "file-browser";
|
||||||
extensionName = "file_browser";
|
extensionName = "file_browser";
|
||||||
package = "telescope-file-browser-nvim";
|
package = "telescope-file-browser-nvim";
|
||||||
|
@ -183,7 +179,7 @@ telescopeHelpers.mkExtension {
|
||||||
Show the current relative path from cwd as the prompt prefix.
|
Show the current relative path from cwd as the prompt prefix.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
mappings = telescopeHelpers.mkMappingsOption {
|
mappings = mkMappingsOption {
|
||||||
insertDefaults = ''
|
insertDefaults = ''
|
||||||
{
|
{
|
||||||
"<A-c>" = "require('telescope._extensions.file_browser.actions').create";
|
"<A-c>" = "require('telescope._extensions.file_browser.actions').create";
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrStr;
|
inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrStr;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension {
|
mkExtension {
|
||||||
name = "frecency";
|
name = "frecency";
|
||||||
package = "telescope-frecency-nvim";
|
package = "telescope-frecency-nvim";
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension {
|
mkExtension {
|
||||||
name = "fzf-native";
|
name = "fzf-native";
|
||||||
extensionName = "fzf";
|
extensionName = "fzf";
|
||||||
package = "telescope-fzf-native-nvim";
|
package = "telescope-fzf-native-nvim";
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension {
|
mkExtension {
|
||||||
name = "fzy-native";
|
name = "fzy-native";
|
||||||
extensionName = "fzy_native";
|
extensionName = "fzy_native";
|
||||||
package = "telescope-fzy-native-nvim";
|
package = "telescope-fzy-native-nvim";
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; };
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
telescopeHelpers.mkExtension {
|
mkExtension {
|
||||||
name = "live-grep-args";
|
name = "live-grep-args";
|
||||||
extensionName = "live_grep_args";
|
extensionName = "live_grep_args";
|
||||||
package = "telescope-live-grep-args-nvim";
|
package = "telescope-live-grep-args-nvim";
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
|
|
||||||
telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; };
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
telescopeHelpers.mkExtension {
|
mkExtension {
|
||||||
name = "manix";
|
name = "manix";
|
||||||
package = "telescope-manix";
|
package = "telescope-manix";
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension {
|
mkExtension {
|
||||||
name = "media-files";
|
name = "media-files";
|
||||||
extensionName = "media_files";
|
extensionName = "media_files";
|
||||||
package = "telescope-media-files-nvim";
|
package = "telescope-media-files-nvim";
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
{
|
let
|
||||||
lib,
|
mkExtension = import ./_mk-extension.nix;
|
||||||
config,
|
in
|
||||||
pkgs,
|
mkExtension {
|
||||||
...
|
|
||||||
}:
|
|
||||||
(import ./_helpers.nix { inherit lib config pkgs; }).mkExtension {
|
|
||||||
name = "ui-select";
|
name = "ui-select";
|
||||||
package = "telescope-ui-select-nvim";
|
package = "telescope-ui-select-nvim";
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
inherit (lib.nixvim) defaultNullOpts mkNullOrOption;
|
inherit (lib.nixvim) defaultNullOpts mkNullOrOption;
|
||||||
telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; };
|
inherit (import ./_helpers.nix lib) mkMappingsOption;
|
||||||
|
mkExtension = import ./_mk-extension.nix;
|
||||||
in
|
in
|
||||||
telescopeHelpers.mkExtension {
|
mkExtension {
|
||||||
name = "undo";
|
name = "undo";
|
||||||
package = "telescope-undo-nvim";
|
package = "telescope-undo-nvim";
|
||||||
|
|
||||||
|
@ -84,7 +80,7 @@ telescopeHelpers.mkExtension {
|
||||||
Can be set to a [Lua date format string](https://www.lua.org/pil/22.1.html).
|
Can be set to a [Lua date format string](https://www.lua.org/pil/22.1.html).
|
||||||
'';
|
'';
|
||||||
|
|
||||||
mappings = telescopeHelpers.mkMappingsOption {
|
mappings = mkMappingsOption {
|
||||||
insertDefaults = ''
|
insertDefaults = ''
|
||||||
{
|
{
|
||||||
"<cr>" = "require('telescope-undo.actions').yank_additions";
|
"<cr>" = "require('telescope-undo.actions').yank_additions";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue