From a0d6d8407fcb20a44320583c2754be713f3a33de Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 14 Jan 2025 16:44:17 +0300 Subject: [PATCH 1/5] plugins/utility: order imports alphabetically --- modules/plugins/utility/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/plugins/utility/default.nix b/modules/plugins/utility/default.nix index 686295e2..6d20e3de 100644 --- a/modules/plugins/utility/default.nix +++ b/modules/plugins/utility/default.nix @@ -1,18 +1,17 @@ { imports = [ - ./outline ./binds ./ccc + ./diffview ./gestures - ./motion - ./new-file-template - ./telescope ./icon-picker ./images - ./telescope - ./diffview - ./wakatime - ./surround + ./motion + ./new-file-template + ./outline ./preview + ./surround + ./telescope + ./wakatime ]; } From 6594409a2506298b43734b31cc5329f2974df2b1 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 14 Jan 2025 16:45:08 +0300 Subject: [PATCH 2/5] utility/telescope: add custom extensions API; clean up setupOptions --- modules/plugins/utility/telescope/config.nix | 11 ++- .../plugins/utility/telescope/telescope.nix | 91 +++++++++++++------ 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index 95f81327..73d5e517 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -5,8 +5,8 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.strings) optionalString; - inherit (lib.lists) optionals; + inherit (lib.strings) optionalString concatMapStringsSep; + inherit (lib.lists) optionals concatLists; inherit (lib.nvim.binds) pushDownDefault mkKeymap; cfg = config.vim.telescope; @@ -16,7 +16,7 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = ["plenary-nvim"]; + startPlugins = ["plenary-nvim"] ++ concatLists (map (x: x.packages) cfg.extensions); lazy.plugins.telescope = { package = "telescope"; @@ -28,11 +28,14 @@ in { vim.g.loaded_telescope = nil ''; - after = '' + after = let + enabledExtensions = map (x: x.name) cfg.extensions; + in '' local telescope = require("telescope") ${optionalString config.vim.ui.noice.enable "telescope.load_extension('noice')"} ${optionalString config.vim.notify.nvim-notify.enable "telescope.load_extension('notify')"} ${optionalString config.vim.projects.project-nvim.enable "telescope.load_extension('projects')"} + ${concatMapStringsSep "\n" (x: "telescope.load_extension('${x}')") enabledExtensions} ''; cmd = ["Telescope"]; diff --git a/modules/plugins/utility/telescope/telescope.nix b/modules/plugins/utility/telescope/telescope.nix index cf9c5cd8..29477db6 100644 --- a/modules/plugins/utility/telescope/telescope.nix +++ b/modules/plugins/utility/telescope/telescope.nix @@ -4,16 +4,12 @@ ... }: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) int str listOf float bool either enum submodule attrsOf; + inherit (lib.types) int str listOf float bool either enum submodule attrsOf anything package; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; setupOptions = { defaults = { vimgrep_arguments = mkOption { - description = '' - Defines the command that will be used for `live_grep` and `grep_string` pickers. - Make sure that color is set to `never` because telescope does not yet interpret color codes. - ''; type = listOf str; default = [ "${pkgs.ripgrep}/bin/rg" @@ -26,53 +22,65 @@ "--hidden" "--no-ignore" ]; + + description = '' + Defines the command that will be used for `live_grep` and `grep_string` pickers. + Make sure that color is set to `never` because telescope does not yet interpret color codes. + ''; }; + pickers.find_command = mkOption { - description = "cmd to use for finding files"; type = either (listOf str) luaInline; default = ["${pkgs.fd}/bin/fd"]; + description = '' + Command to use for finding files. If using an executable from `PATH` then you must + make sure that the package is available in [](#opt-vim.extraPackages). + ''; }; + prompt_prefix = mkOption { - description = "Shown in front of Telescope's prompt"; type = str; default = "  "; + description = "Shown in front of Telescope's prompt"; }; + selection_caret = mkOption { + type = str; + default = " "; description = "Character(s) to show in front of the current selection"; - type = str; - default = " "; }; + entry_prefix = mkOption { - description = "Prefix in front of each result entry. Current selection not included."; type = str; default = " "; + description = "Prefix in front of each result entry. Current selection not included."; }; + initial_mode = mkOption { - description = "Determines in which mode telescope starts."; type = enum ["insert" "normal"]; default = "insert"; + description = "Determines in which mode telescope starts."; }; + selection_strategy = mkOption { - description = "Determines how the cursor acts after each sort iteration."; type = enum ["reset" "follow" "row" "closest" "none"]; default = "reset"; + description = "Determines how the cursor acts after each sort iteration."; }; + sorting_strategy = mkOption { - description = ''Determines the direction "better" results are sorted towards.''; type = enum ["descending" "ascending"]; default = "ascending"; + description = ''Determines the direction "better" results are sorted towards.''; }; + layout_strategy = mkOption { - description = "Determines the default layout of Telescope pickers. See `:help telescope.layout`."; type = str; default = "horizontal"; + description = "Determines the default layout of Telescope pickers. See `:help telescope.layout`."; }; + layout_config = mkOption { - description = '' - Determines the default configuration values for layout strategies. - See telescope.layout for details of the configurations options for - each strategy. - ''; default = {}; type = submodule { options = { @@ -117,33 +125,57 @@ }; }; }; + + description = '' + Determines the default configuration values for layout strategies. + See `telescope.layout` for details of the configurations options for + each strategy. + ''; }; + file_ignore_patterns = mkOption { - description = "A table of lua regex that define the files that should be ignored."; type = listOf str; default = ["node_modules" ".git/" "dist/" "build/" "target/" "result/"]; + description = "A table of lua regex that define the files that should be ignored."; }; + color_devicons = mkOption { - description = "Boolean if devicons should be enabled or not."; type = bool; default = true; + description = "Boolean if devicons should be enabled or not."; }; + path_display = mkOption { - description = "Determines how file paths are displayed."; type = listOf (enum ["hidden" "tail" "absolute" "smart" "shorten" "truncate"]); default = ["absolute"]; + description = "Determines how file paths are displayed."; }; + set_env = mkOption { - description = "Set an environment for term_previewer"; type = attrsOf str; - default = { - COLORTERM = "truecolor"; - }; + default = {COLORTERM = "truecolor";}; + description = "Set an environment for term_previewer"; }; + winblend = mkOption { - description = "pseudo-transparency of keymap hints floating window"; type = int; default = 0; + description = "pseudo-transparency of keymap hints floating window"; + }; + }; + }; + + extensionOpts = { + options = { + name = mkOption { + type = str; + description = "Name of the extension, will be used to load it with a `require`"; + }; + + packages = mkOption { + type = listOf (either str package); + default = []; + description = "Package or packages providing the Telescope extension to be loaded."; }; }; }; @@ -178,5 +210,10 @@ in { enable = mkEnableOption "telescope.nvim: multi-purpose search and picker utility"; setupOpts = mkPluginSetupOption "Telescope" setupOptions; + extensions = mkOption { + type = listOf (attrsOf (submodule extensionOpts)); + default = []; + description = "TODO"; + }; }; } From 5f1302321a83fe7661cd367f9fc75e18a11d84f8 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 14 Jan 2025 17:24:51 +0300 Subject: [PATCH 3/5] utility/telescope: concat extension setup sets --- .../plugins/utility/telescope/telescope.nix | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/modules/plugins/utility/telescope/telescope.nix b/modules/plugins/utility/telescope/telescope.nix index 29477db6..1305a1dc 100644 --- a/modules/plugins/utility/telescope/telescope.nix +++ b/modules/plugins/utility/telescope/telescope.nix @@ -1,12 +1,15 @@ { + config, pkgs, lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; + inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.types) int str listOf float bool either enum submodule attrsOf anything package; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; + + cfg = config.vim.telescope; setupOptions = { defaults = { vimgrep_arguments = mkOption { @@ -33,7 +36,7 @@ type = either (listOf str) luaInline; default = ["${pkgs.fd}/bin/fd"]; description = '' - Command to use for finding files. If using an executable from `PATH` then you must + Command to use for finding files. If using an executable from {env}`PATH` then you must make sure that the package is available in [](#opt-vim.extraPackages). ''; }; @@ -90,17 +93,20 @@ type = str; default = "top"; }; + preview_width = mkOption { description = ""; type = float; default = 0.55; }; + results_width = mkOption { description = ""; type = float; default = 0.8; }; }; + vertical = { mirror = mkOption { description = ""; @@ -108,16 +114,19 @@ default = false; }; }; + width = mkOption { description = ""; type = float; default = 0.8; }; + height = mkOption { description = ""; type = float; default = 0.8; }; + preview_cutoff = mkOption { description = ""; type = int; @@ -162,6 +171,12 @@ default = 0; description = "pseudo-transparency of keymap hints floating window"; }; + + extensions = mkOption { + type = attrsOf anything; + default = builtins.foldl' (acc: x: acc // (x.setup or {})) {} cfg.extensions; + description = "Attribute set containing per-extension settings for Telescope"; + }; }; }; @@ -177,6 +192,13 @@ default = []; description = "Package or packages providing the Telescope extension to be loaded."; }; + + setup = mkOption { + type = attrsOf anything; + default = {}; + example = {fzf = {fuzzy = true;};}; + description = "Named attribute set to be inserted into Telescope's extensions table."; + }; }; }; in { @@ -210,10 +232,24 @@ in { enable = mkEnableOption "telescope.nvim: multi-purpose search and picker utility"; setupOpts = mkPluginSetupOption "Telescope" setupOptions; + extensions = mkOption { type = listOf (attrsOf (submodule extensionOpts)); default = []; - description = "TODO"; + example = literalExpression '' + [ + { + name = "fzf"; + packages = [pkgs.vimPlugins.telescope-fzf-native-nvim]; + setup = {fzf = {fuzzy = true;};}; + } + ] + ''; + description = '' + Individual extension configurations containing **name**, **packages** and **setup** + fields to resolve dependencies, handle `load_extension` calls and add the `setup` + table into the `extensions` portion of Telescope's setup table. + ''; }; }; } From 45e4a3bd6ff61b750ed4350387b82731cd2dec2e Mon Sep 17 00:00:00 2001 From: raf Date: Mon, 17 Feb 2025 17:43:49 +0000 Subject: [PATCH 4/5] telescope: fix extensions type Co-authored-by: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> --- modules/plugins/utility/telescope/telescope.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/utility/telescope/telescope.nix b/modules/plugins/utility/telescope/telescope.nix index 25bb6223..0ab80380 100644 --- a/modules/plugins/utility/telescope/telescope.nix +++ b/modules/plugins/utility/telescope/telescope.nix @@ -228,7 +228,7 @@ in { setupOpts = mkPluginSetupOption "Telescope" setupOptions; extensions = mkOption { - type = listOf (attrsOf (submodule extensionOpts)); + type = listOf (submodule extensionOpts); default = []; example = literalExpression '' [ From 7644edfe2b5a170c835098d693d17ab3a28e8b32 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 11 Jun 2025 10:10:47 +0300 Subject: [PATCH 5/5] utility/telescope: document missing layout options --- .../plugins/utility/telescope/telescope.nix | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/plugins/utility/telescope/telescope.nix b/modules/plugins/utility/telescope/telescope.nix index 7c01bb8f..9ed6f263 100644 --- a/modules/plugins/utility/telescope/telescope.nix +++ b/modules/plugins/utility/telescope/telescope.nix @@ -95,42 +95,42 @@ options = { horizontal = { prompt_position = mkOption { - description = ""; - type = str; + type = enum ["top" "bottom"]; default = "top"; + description = "Where to place prompt window"; }; preview_width = mkOption { - description = ""; type = float; default = 0.55; + description = "Change the width of Telescope's preview window"; }; }; vertical = { mirror = mkOption { - description = ""; type = bool; default = false; + description = "Flip the location of the results/prompt and preview windows"; }; }; width = mkOption { - description = ""; type = float; default = 0.8; + description = "How wide to make Telescope's entire layout"; }; height = mkOption { - description = ""; type = float; default = 0.8; + description = "How tall to make Telescope's entire layout"; }; preview_cutoff = mkOption { - description = ""; type = int; default = 120; + description = "When lines are less than this value, the preview will be disabled"; }; }; }; @@ -145,13 +145,10 @@ file_ignore_patterns = mkOption { type = listOf str; default = ["node_modules" "%.git/" "dist/" "build/" "target/" "result/"]; + description = "File patterns to omit from Telescope results"; }; - color_devicons = mkOption { - type = bool; - default = true; - description = "Boolean if devicons should be enabled or not."; - }; + color_devicons = mkEnableOption "colored devicons"; path_display = mkOption { type = listOf (enum ["hidden" "tail" "absolute" "smart" "shorten" "truncate"]); @@ -168,7 +165,7 @@ winblend = mkOption { type = int; default = 0; - description = "pseudo-transparency of keymap hints floating window"; + description = "Pseudo-transparency of keymap hints floating window"; }; extensions = mkOption {