telescope: lazy load

This commit is contained in:
Ching Pei Yang 2024-09-30 21:58:21 +02:00 committed by Ching Pei Yang
parent 7e144707d9
commit bc6597c36a
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9

View file

@ -4,11 +4,11 @@
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) pushDownDefault;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings;
inherit (lib.strings) optionalString;
inherit (lib.lists) optionals;
inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding;
cfg = config.vim.telescope;
self = import ./telescope.nix {inherit pkgs lib;};
@ -18,45 +18,58 @@
in {
config = mkIf cfg.enable {
vim = {
startPlugins = [
"telescope"
"plenary-nvim"
];
startPlugins = ["plenary-nvim"];
maps.normal = mkMerge [
(mkSetBinding mappings.findFiles "<cmd> Telescope find_files<CR>")
(mkSetBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>")
(mkSetBinding mappings.buffers "<cmd> Telescope buffers<CR>")
(mkSetBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.resume "<cmd> Telescope resume<CR>")
lazy.plugins = [
{
package = "telescope";
setupModule = "telescope";
inherit (cfg) setupOpts;
# FIXME: how do I deal with extensions? set all as deps?
after = ''
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')"}
'';
(mkSetBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
cmd = ["Telescope"];
(mkIf config.vim.lsp.enable (mkMerge [
(mkSetBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
keys =
[
(mkSetLznBinding mappings.findFiles "<cmd> Telescope find_files<CR>")
(mkSetLznBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>")
(mkSetLznBinding mappings.buffers "<cmd> Telescope buffers<CR>")
(mkSetLznBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetLznBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
(mkSetBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
(mkSetBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
]))
(mkSetLznBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetLznBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetLznBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetLznBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetLznBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
]
++ (optionals config.vim.lsp.enable [
(mkSetLznBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetLznBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
(
mkIf config.vim.treesitter.enable
(mkSetBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
)
(
mkIf config.vim.projects.project-nvim.enable
(mkSetBinding mappings.findProjects "<cmd> Telescope projects<CR>")
(mkSetLznBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
(mkSetLznBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetLznBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
(mkSetLznBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetLznBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
])
++ (
optionals config.vim.treesitter.enable [
(mkSetLznBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
]
)
++ (
optionals config.vim.projects.project-nvim.enable [
(mkSetLznBinding mappings.findProjects "<cmd Telescope projects<CR>")
]
);
}
];
binds.whichKey.register = pushDownDefault {
@ -66,29 +79,6 @@ in {
"<leader>fv" = "Telescope Git";
"<leader>fvc" = "Commits";
};
pluginRC.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 ""
}
'';
};
};
}