From ba90aadc60d7972074329b75f044a024ddd244b5 Mon Sep 17 00:00:00 2001 From: Mateus Auler Date: Sat, 13 Apr 2024 15:15:38 -0300 Subject: [PATCH] neovim: Fix telescope's config --- .../common/neovim/plugins/telescope.nix | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/hm-modules/common/neovim/plugins/telescope.nix b/hm-modules/common/neovim/plugins/telescope.nix index a4ae94d..9752f9a 100644 --- a/hm-modules/common/neovim/plugins/telescope.nix +++ b/hm-modules/common/neovim/plugins/telescope.nix @@ -1,34 +1,48 @@ -{ config, lib, pkgs, ... }: +{ config, lib, nixpkgs-channel, pkgs, ... }: let cfg = config.modules.neovim; cfg-plug = config.programs.nixvim.plugins; + + keymaps = { + "ff" = { action = "find_files"; options.desc = "Telescope: Find files"; }; + "fg" = { action = "live_grep"; options.desc = "Telescope: Live grep"; }; + "fb" = { action = "buffers"; options.desc = "Telescope: Buffers"; }; + "fh" = { action = "help_tags"; options.desc = "Telescope: Help tags"; }; + }; + + settings = { + # FIXME: Use mkRaw helper once I figure out how to get helpers working + defaults.vimgrep_arguments.__raw = /* lua */ '' + (function() + local telescopeConfig = require("telescope.config") + local vimgrep_arguments = { unpack(telescopeConfig.values.vimgrep_arguments) } + table.insert(vimgrep_arguments, "--hidden") + table.insert(vimgrep_arguments, "--glob") + table.insert(vimgrep_arguments, "!**/.git/*") + return vimgrep_arguments + end)() + ''; + + pickers.find_files.find_command = [ "rg" "--files" "--hidden" "--glob" "!**/.git/*" ]; + }; in lib.mkIf cfg.enable { programs.nixvim = { - extraPackages = lib.optional cfg-plug.telescope.enable pkgs.fd; + extraPackages = lib.optionals cfg-plug.telescope.enable [ pkgs.fd pkgs.ripgrep ]; plugins.telescope = { - keymaps = { - "ff" = { action = "find_files"; desc = "Telescope: Find files"; }; - "fg" = { action = "live_grep"; desc = "Telescope: Live grep"; }; - "fb" = { action = "buffers"; desc = "Telescope: Buffers"; }; - "fh" = { action = "help_tags"; desc = "Telescope: Help tags"; }; - }; - - # FIXME: Use mkRaw helper once I figure out how to get helpers working - defaults.vimgrep_arguments.__raw = /* lua */ '' - (function() - local telescopeConfig = require("telescope.config") - local vimgrep_arguments = { unpack(telescopeConfig.values.vimgrep_arguments) } - table.insert(vimgrep_arguments, "--hidden") - table.insert(vimgrep_arguments, "--glob") - table.insert(vimgrep_arguments, "!**/.git/*") - return vimgrep_arguments - end)() - ''; - - extraOptions.pickers.find_files.find_command = [ "rg" "--files" "--hidden" "--glob" "!**/.git/*" ]; - }; + keymaps = lib.mapAttrs + (_: value: + if nixpkgs-channel == "stable" then + { inherit (value) action; } // value.options + else + value + ) + keymaps; + } // (if nixpkgs-channel == "stable" then { + inherit (settings) defaults; + extraOptions = { inherit (settings) pickers; }; + } else { inherit settings; }); }; }