Skip to content

Commit

Permalink
plugins/telescope: migrate helpers -> lib.nixvim
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Aug 22, 2024
1 parent d7b506e commit 83c2844
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 446 deletions.
18 changes: 10 additions & 8 deletions plugins/telescope/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
inherit (lib.nixvim) keymaps mkNullOrOption toLuaObject;
in
# TODO:add support for additional filetypes. This requires autocommands!
helpers.neovim-plugin.mkNeovimPlugin config {
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
name = "telescope";
originalName = "telescope.nvim";
defaultPackage = pkgs.vimPlugins.telescope-nvim;
Expand Down Expand Up @@ -45,8 +47,8 @@ helpers.neovim-plugin.mkNeovimPlugin config {
type = types.str;
description = "The telescope action to run.";
};
mode = helpers.keymaps.mkModeOption "n";
options = helpers.keymaps.mapConfigOptions;
mode = keymaps.mkModeOption "n";
options = keymaps.mapConfigOptions;
};
})
);
Expand Down Expand Up @@ -105,9 +107,9 @@ helpers.neovim-plugin.mkNeovimPlugin config {
) cfg.keymaps;

extraConfigLua = ''
require('telescope').setup(${helpers.toLuaObject cfg.settings})
require('telescope').setup(${toLuaObject cfg.settings})
local __telescopeExtensions = ${helpers.toLuaObject cfg.enabledExtensions}
local __telescopeExtensions = ${toLuaObject cfg.enabledExtensions}
for i, extension in ipairs(__telescopeExtensions) do
require('telescope').load_extension(extension)
end
Expand All @@ -118,11 +120,11 @@ helpers.neovim-plugin.mkNeovimPlugin config {
};

settingsOptions = {
defaults = helpers.mkNullOrOption (with types; attrsOf anything) ''
defaults = mkNullOrOption (with types; attrsOf anything) ''
Default configuration for telescope.
'';

pickers = helpers.mkNullOrOption (with types; attrsOf anything) ''
pickers = mkNullOrOption (with types; attrsOf anything) ''
Default configuration for builtin pickers.
'';

Expand Down
20 changes: 9 additions & 11 deletions plugins/telescope/extensions/_helpers.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
lib,
config,
helpers,
...
}:
{ lib, config, ... }:
with lib;
let
inherit (lib.nixvim) mkPluginPackageOption mkSettingsOption toSnakeCase;
in
rec {
mkExtension =
{
Expand Down Expand Up @@ -36,17 +34,17 @@ rec {
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)

optionPathSnakeCase = map helpers.toSnakeCase optionPath;
optionPathSnakeCase = map toSnakeCase optionPath;
in
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);

options.plugins.telescope.extensions.${name} = {
enable = mkEnableOption "the `${name}` telescope extension";

package = helpers.mkPluginPackageOption name defaultPackage;
package = mkPluginPackageOption name defaultPackage;

settings = helpers.mkSettingsOption {
settings = mkSettingsOption {
description = "settings for the `${name}` telescope extension.";
options = settingsOptions;
example = settingsExample;
Expand All @@ -73,7 +71,7 @@ rec {
mkModeMappingsOption =
mode: defaults:
mkOption {
type = with helpers.nixvimTypes; attrsOf strLuaFn;
type = with types; attrsOf strLuaFn;
default = { };
description = ''
Keymaps in ${mode} mode.
Expand All @@ -83,7 +81,7 @@ rec {
${defaults}
```
'';
apply = mapAttrs (_: helpers.mkRaw);
apply = mapAttrs (_: mkRaw);
};

mkMappingsOption =
Expand Down
63 changes: 28 additions & 35 deletions plugins/telescope/extensions/file-browser.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
telescopeHelpers = import ./_helpers.nix {
inherit
lib
helpers
config
pkgs
;
};
telescopeHelpers = import ./_helpers.nix { inherit lib config pkgs; };
inherit (lib.nixvim) defaultNullOpts mkNullOrStr;
in
telescopeHelpers.mkExtension {
name = "file-browser";
Expand Down Expand Up @@ -79,58 +72,58 @@ telescopeHelpers.mkExtension {
];

settingsOptions = {
theme = helpers.mkNullOrStr ''
theme = mkNullOrStr ''
Custom theme, will use your global theme by default.
'';

path = helpers.defaultNullOpts.mkStr { __raw = "vim.loop.cwd()"; } ''
path = defaultNullOpts.mkStr { __raw = "vim.loop.cwd()"; } ''
Directory to browse files from.
`vim.fn.expanded` automatically.
'';

cwd = helpers.defaultNullOpts.mkStr { __raw = "vim.loop.cwd()"; } ''
cwd = defaultNullOpts.mkStr { __raw = "vim.loop.cwd()"; } ''
Directory to browse folders from.
`vim.fn.expanded` automatically.
'';

cwd_to_path = helpers.defaultNullOpts.mkBool false ''
cwd_to_path = defaultNullOpts.mkBool false ''
Whether folder browser is launched from `path` rather than `cwd`.
'';

grouped = helpers.defaultNullOpts.mkBool false ''
grouped = defaultNullOpts.mkBool false ''
Group initial sorting by directories and then files.
'';

files = helpers.defaultNullOpts.mkBool true ''
files = defaultNullOpts.mkBool true ''
Start in file (true) or folder (false) browser.
'';

add_dirs = helpers.defaultNullOpts.mkBool true ''
add_dirs = defaultNullOpts.mkBool true ''
Whether the file browser shows folders.
'';

depth = helpers.defaultNullOpts.mkUnsignedInt 1 ''
depth = defaultNullOpts.mkUnsignedInt 1 ''
File tree depth to display, `false` for unlimited depth.
'';

auto_depth = helpers.defaultNullOpts.mkBool false ''
auto_depth = defaultNullOpts.mkBool false ''
Unlimit or set `depth` to `auto_depth` & unset grouped on prompt for file_browser.
'';

select_buffer = helpers.defaultNullOpts.mkBool false ''
select_buffer = defaultNullOpts.mkBool false ''
Select current buffer if possible.
May imply `hidden=true`.
'';

hidden =
helpers.defaultNullOpts.mkNullable
defaultNullOpts.mkNullable
(
with types;
either bool (submodule {
options = {
file_browser = helpers.defaultNullOpts.mkBool false "";
file_browser = defaultNullOpts.mkBool false "";

folder_browser = helpers.defaultNullOpts.mkBool false "";
folder_browser = defaultNullOpts.mkBool false "";
};
})
)
Expand All @@ -140,53 +133,53 @@ telescopeHelpers.mkExtension {
}
"Determines whether to show hidden files or not.";

respect_gitignore = helpers.defaultNullOpts.mkBool false ''
respect_gitignore = defaultNullOpts.mkBool false ''
Induces slow-down w/ plenary finder (true if `fd` available).
'';

browse_files = helpers.defaultNullOpts.mkLuaFn "require('telescope._extensions.file_browser.finders').browse_files" "A custom lua function to override for the file browser.";
browse_files = defaultNullOpts.mkLuaFn "require('telescope._extensions.file_browser.finders').browse_files" "A custom lua function to override for the file browser.";

browse_folders = helpers.defaultNullOpts.mkLuaFn "require('telescope._extensions.file_browser.finders').browse_folders" "A custom lua function to override for the folder browser.";
browse_folders = defaultNullOpts.mkLuaFn "require('telescope._extensions.file_browser.finders').browse_folders" "A custom lua function to override for the folder browser.";

hide_parent_dir = helpers.defaultNullOpts.mkBool false ''
hide_parent_dir = defaultNullOpts.mkBool false ''
Hide `../` in the file browser.
'';

collapse_dirs = helpers.defaultNullOpts.mkBool false ''
collapse_dirs = defaultNullOpts.mkBool false ''
Skip with only a single (possibly hidden) sub-dir in file_browser.
'';

quiet = helpers.defaultNullOpts.mkBool false ''
quiet = defaultNullOpts.mkBool false ''
Suppress any notification from file_browser actions.
'';

dir_icon = helpers.defaultNullOpts.mkStr "" ''
dir_icon = defaultNullOpts.mkStr "" ''
Change the icon for a directory.
'';

dir_icon_hl = helpers.defaultNullOpts.mkStr "Default" ''
dir_icon_hl = defaultNullOpts.mkStr "Default" ''
Change the highlight group of dir icon.
'';

display_stat = helpers.defaultNullOpts.mkAttrsOf types.anything {
display_stat = defaultNullOpts.mkAttrsOf types.anything {
date = true;
size = true;
mode = true;
} "Ordered stat; see upstream for more info.";

hijack_netrw = helpers.defaultNullOpts.mkBool false ''
hijack_netrw = defaultNullOpts.mkBool false ''
Use telescope file browser when opening directory paths.
'';

use_fd = helpers.defaultNullOpts.mkBool true ''
use_fd = defaultNullOpts.mkBool true ''
Use `fd` if available over `plenary.scandir`.
'';

git_status = helpers.defaultNullOpts.mkBool true ''
git_status = defaultNullOpts.mkBool true ''
Show the git status of files (true if `git` is found).
'';

prompt_path = helpers.defaultNullOpts.mkBool false ''
prompt_path = defaultNullOpts.mkBool false ''
Show the current relative path from cwd as the prompt prefix.
'';

Expand Down
Loading

0 comments on commit 83c2844

Please sign in to comment.