{ pkgs, config, lib, ... }: let inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding; inherit (lib.nvim.dag) entryAnywhere; # TODO: move this to its own module inherit (lib) pushDownDefault; inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.telescope; self = import ./telescope.nix {inherit pkgs lib;}; mappingDefinitions = self.options.vim.telescope.mappings; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; in { config = mkIf (cfg.enable) { vim.startPlugins = [ "telescope" ]; vim.maps.normal = mkMerge [ (mkSetBinding mappings.findFiles " Telescope find_files") (mkSetBinding mappings.liveGrep " Telescope live_grep") (mkSetBinding mappings.buffers " Telescope buffers") (mkSetBinding mappings.helpTags " Telescope help_tags") (mkSetBinding mappings.open " Telescope") (mkSetBinding mappings.gitCommits " Telescope git_commits") (mkSetBinding mappings.gitBufferCommits " Telescope git_bcommits") (mkSetBinding mappings.gitBranches " Telescope git_branches") (mkSetBinding mappings.gitStatus " Telescope git_status") (mkSetBinding mappings.gitStash " Telescope git_stash") (mkIf config.vim.lsp.enable (mkMerge [ (mkSetBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") (mkSetBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") (mkSetBinding mappings.lspReferences " Telescope lsp_references") (mkSetBinding mappings.lspImplementations " Telescope lsp_implementations") (mkSetBinding mappings.lspDefinitions " Telescope lsp_definitions") (mkSetBinding mappings.lspTypeDefinitions " Telescope lsp_type_definitions") (mkSetBinding mappings.diagnostics " Telescope diagnostics") ])) ( mkIf config.vim.treesitter.enable (mkSetBinding mappings.treesitter " Telescope treesitter") ) ( mkIf config.vim.projects.project-nvim.enable (mkSetBinding mappings.findProjects "") ) ]; vim.binds.whichKey.register = pushDownDefault { "f" = "+Telescope"; "fl" = "Telescope LSP"; "fm" = "Cellular Automaton"; "fv" = "Telescope Git"; "fvc" = "Commits"; }; vim.luaConfigRC.telescope = entryAnywhere '' local telescope = require('telescope') telescope.setup(${toLuaObject cfg.setupOpts}) ${ if config.vim.ui.noice.enable then "telescope.load_extension('noice')" else "" } ${ if config.vim.notify.nvim-notify.enable then "telescope.load_extension('notify')" else "" } ${ if config.vim.projects.project-nvim.enable then "telescope.load_extension('projects')" else "" } ''; }; }