From 6ede63c170b25af745949c58915b50c9dac0897c Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:55:37 +0200 Subject: [PATCH 01/19] flake: add lz.n and lzn-auto-require --- flake.lock | 35 +++++++++++++++++++++++++++++++++++ flake.nix | 11 +++++++++++ 2 files changed, 46 insertions(+) diff --git a/flake.lock b/flake.lock index 3e267311..aa5763e3 100644 --- a/flake.lock +++ b/flake.lock @@ -828,6 +828,39 @@ "type": "github" } }, + "plugin-lz-n": { + "flake": false, + "locked": { + "lastModified": 1727574854, + "narHash": "sha256-qDWNleR2NHFkiEKE/+LNVOBRwEeskMC4dWTl5BTyZuE=", + "owner": "nvim-neorocks", + "repo": "lz.n", + "rev": "470173e3cbef763c6d1b918f3f129b67db75e1f8", + "type": "github" + }, + "original": { + "owner": "nvim-neorocks", + "repo": "lz.n", + "type": "github" + } + }, + "plugin-lzn-auto-require": { + "flake": false, + "locked": { + "lastModified": 1727636949, + "narHash": "sha256-BAOzN+XOrFAJwHmsF8JtZ2EyjP9283FD/I2TbFqGSEw=", + "owner": "horriblename", + "repo": "lzn-auto-require", + "rev": "55ecd60831dac8c01d6f3dcb63a30a63a1690eb8", + "type": "github" + }, + "original": { + "owner": "horriblename", + "ref": "require-rewrite", + "repo": "lzn-auto-require", + "type": "github" + } + }, "plugin-mind-nvim": { "flake": false, "locked": { @@ -1859,6 +1892,8 @@ "plugin-lspkind": "plugin-lspkind", "plugin-lspsaga": "plugin-lspsaga", "plugin-lualine": "plugin-lualine", + "plugin-lz-n": "plugin-lz-n", + "plugin-lzn-auto-require": "plugin-lzn-auto-require", "plugin-mind-nvim": "plugin-mind-nvim", "plugin-minimap-vim": "plugin-minimap-vim", "plugin-modes-nvim": "plugin-modes-nvim", diff --git a/flake.nix b/flake.nix index c4a1a2a8..994477af 100644 --- a/flake.nix +++ b/flake.nix @@ -113,6 +113,17 @@ }; ## Plugins + # Lazy loading + plugin-lz-n = { + url = "github:nvim-neorocks/lz.n"; + flake = false; + }; + + plugin-lzn-auto-require = { + url = "github:horriblename/lzn-auto-require/require-rewrite"; + flake = false; + }; + # LSP plugins plugin-nvim-lspconfig = { url = "github:neovim/nvim-lspconfig"; From ea0ee39687d6274bfe481772d17e57eae1c35950 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:56:31 +0200 Subject: [PATCH 02/19] lazy: init module --- modules/modules.nix | 1 + modules/wrapper/lazy/config.nix | 85 +++++++++++++ modules/wrapper/lazy/default.nix | 6 + modules/wrapper/lazy/lazy.nix | 205 +++++++++++++++++++++++++++++++ 4 files changed, 297 insertions(+) create mode 100644 modules/wrapper/lazy/config.nix create mode 100644 modules/wrapper/lazy/default.nix create mode 100644 modules/wrapper/lazy/lazy.nix diff --git a/modules/modules.nix b/modules/modules.nix index 1204e43f..784c413e 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -50,6 +50,7 @@ "build" "rc" "warnings" + "lazy" ]; # Extra modules, such as deprecation warnings diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix new file mode 100644 index 00000000..5db378bc --- /dev/null +++ b/modules/wrapper/lazy/config.nix @@ -0,0 +1,85 @@ +{ + lib, + config, + ... +}: let + inherit (builtins) toJSON typeOf head length tryEval filter; + inherit (lib.modules) mkIf; + inherit (lib.generators) mkLuaInline; + inherit (lib.strings) optionalString; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryBefore; + cfg = config.vim.lazy; + + toLuaLznKeySpec = { + desc, + noremap, + expr, + nowait, + ft, + key, + action, + lua, + mode, + }: { + "@1" = key; + "@2" = + if lua + then mkLuaInline action + else action; + inherit desc noremap expr nowait ft mode; + }; + + toLuaLznSpec = spec: let + name = + if typeOf spec.package == "string" + then spec.package + else if (spec.package ? pname && (tryEval spec.package.pname).success) + then spec.package.pname + else spec.package.name; + in + (removeAttrs spec ["package" "setupModule" "setupOpts" "keys"]) + // { + "@1" = name; + before = + if spec.before != null + then + mkLuaInline '' + function() + ${spec.before} + end + '' + else null; + + after = + if spec.setupModule == null && spec.after == null + then null + else + mkLuaInline '' + function() + ${ + optionalString (spec.setupModule != null) + "require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" + } + ${optionalString (spec.after != null) spec.after} + end + ''; + + keys = + if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set" + then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys) + # empty list or str or (listOf str) + else spec.keys; + }; + lznSpecs = map toLuaLznSpec cfg.plugins; +in { + config.vim = mkIf cfg.enable { + startPlugins = ["lz-n" "lzn-auto-require"]; + + optPlugins = map (plugin: plugin.package) cfg.plugins; + + luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] '' + require('lz.n').load(${toLuaObject lznSpecs}) + ''; + }; +} diff --git a/modules/wrapper/lazy/default.nix b/modules/wrapper/lazy/default.nix new file mode 100644 index 00000000..fa401272 --- /dev/null +++ b/modules/wrapper/lazy/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./lazy.nix + ./config.nix + ]; +} diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix new file mode 100644 index 00000000..c00b1fe4 --- /dev/null +++ b/modules/wrapper/lazy/lazy.nix @@ -0,0 +1,205 @@ +{lib, ...}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) enum listOf submodule nullOr str bool int attrsOf anything either oneOf; + inherit (lib.nvim.types) pluginType; + inherit (lib.nvim.config) mkBool; + + lznKeysSpec = submodule { + options = { + key = mkOption { + type = nullOr str; + description = "Key to bind to. If key is null this entry is ignored."; + }; + + action = mkOption { + type = nullOr str; + default = null; + description = "Action to trigger."; + }; + lua = mkBool false '' + If true, `action` is considered to be lua code. + Thus, it will not be wrapped in `""`. + ''; + + desc = mkOption { + description = "Description of the key map"; + type = nullOr str; + default = null; + }; + + ft = mkOption { + description = "TBD"; + type = nullOr (listOf str); + default = null; + }; + + mode = mkOption { + description = "Modes to bind in"; + type = listOf str; + default = ["n" "x" "s" "o"]; + }; + + noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; + expr = mkBool false "Means that the action is actually an expression. Equivalent to adding to a map."; + nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; + }; + }; + + lznPluginType = submodule { + options = { + ## Should probably infer from the actual plugin somehow + ## In general this is the name passed to packadd, so the dir name of the plugin + # name = mkOption { + # type= str; + # } + + # Non-lz.n options + + package = mkOption { + type = pluginType; + description = "Plugin package"; + }; + + setupModule = mkOption { + type = nullOr str; + description = "Lua module to run setup function on."; + default = null; + }; + + setupOpts = mkOption { + type = submodule {freeformType = attrsOf anything;}; + description = "Options to pass to the setup function"; + default = {}; + }; + + # lz.n options + + enabled = mkOption { + type = nullOr (either bool str); + description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; + default = null; + }; + + beforeAll = mkOption { + type = nullOr str; + description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; + default = null; + }; + + before = mkOption { + type = nullOr str; + description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; + default = null; + }; + + after = mkOption { + type = nullOr str; + description = "Lua code to run after plugin is loaded. This will be wrapped in a function."; + default = null; + }; + + event = mkOption { + description = "Lazy-load on event"; + default = null; + type = let + event = submodule { + options = { + event = mkOption { + type = nullOr (either str (listOf str)); + description = "Exact event name"; + example = "BufEnter"; + }; + pattern = mkOption { + type = nullOr (either str (listOf str)); + description = "Event pattern"; + example = "BufEnter *.lua"; + }; + }; + }; + in + nullOr (oneOf [str (listOf str) event]); + }; + + cmd = mkOption { + description = "Lazy-load on command"; + default = null; + type = nullOr (either str (listOf str)); + }; + + ft = mkOption { + description = "Lazy-load on filetype"; + default = null; + type = nullOr (either str (listOf str)); + }; + + keys = mkOption { + description = "Lazy-load on key mapping"; + default = null; + type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); + example = '' + keys = [ + { + mode = "n"; + key = "s"; + action = ":DapStepOver"; + desc = "DAP Step Over"; + } + { + mode = ["n", "x"]; + key = "dc"; + action = "function() require('dap').continue() end"; + lua = true; + desc = "DAP Continue"; + } + ] + ''; + }; + + colorscheme = mkOption { + description = "Lazy-load on colorscheme."; + type = nullOr (either str (listOf str)); + default = null; + }; + + priority = mkOption { + type = nullOr int; + description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; + default = null; + }; + + load = mkOption { + type = nullOr str; + default = null; + description = '' + Lua code to override the `vim.g.lz_n.load()` function for a single plugin. + + This will be wrapped in a function + ''; + }; + }; + }; +in { + options.vim.lazy = { + enable = mkEnableOption "plugin lazy-loading" // {default = true;}; + loader = mkOption { + description = "Lazy loader to use"; + type = enum ["lz.n"]; + default = "lz.n"; + }; + + plugins = mkOption { + default = []; + type = listOf lznPluginType; + description = "list of plugins to lazy load"; + example = '' + [ + { + package = "toggleterm-nvim"; + after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end"; + cmd = ["ToggleTerm"]; + } + ] + ''; + }; + }; +} From ae5d39227c4476e86121e8bcf6092ed2dff5040b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:57:03 +0200 Subject: [PATCH 03/19] lzn-auto-require: add init lua code --- modules/wrapper/rc/config.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index 6f9ed1ce..25fc9bcf 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -4,8 +4,8 @@ ... }: let inherit (builtins) map mapAttrs filter; - inherit (lib.attrsets) mapAttrsToList filterAttrs; - inherit (lib.strings) concatLines concatMapStringsSep; + inherit (lib.attrsets) mapAttrsToList; + inherit (lib.strings) concatLines concatMapStringsSep optionalString; inherit (lib.trivial) showWarnings; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere; @@ -55,6 +55,8 @@ in { pluginConfigs = entryAfter ["optionsScript"] pluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; mappings = entryAfter ["extraPluginConfigs"] keymaps; + # FIXME: put this somewhere less stupid + footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require').enable()"); }; builtLuaConfigRC = let From e177e5f1c3c43000b75d0f2d1b538df15e530ba3 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:57:36 +0200 Subject: [PATCH 04/19] wrapper: fix opt plugin format --- modules/default.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index 6a950802..6306da9a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -84,10 +84,7 @@ # built (or "normalized") plugins that are modified builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; - builtOptPlugins = map (package: { - plugin = package; - optional = true; - }) (buildConfigPlugins vimOptions.optPlugins); + builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins); # additional Lua and Python3 packages, mapped to their respective functions # to conform to the format mnw expects. end user should From 74f7367355f1c42db68fc7a3e2c41475f512dbd0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:06 +0200 Subject: [PATCH 05/19] lib.binds: add lz.n variant of bind functions --- lib/binds.nix | 17 ++++ lib/types/plugins.nix | 186 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 202 insertions(+), 1 deletion(-) diff --git a/lib/binds.nix b/lib/binds.nix index 8c9e9a62..ca187f2f 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -67,6 +67,23 @@ mkLuaBinding binding.value action binding.description; pushDownDefault = attr: mapAttrs (_: mkDefault) attr; + + mkLznBinding = mode: key: action: desc: { + inherit mode desc key action; + }; + + mkSetLznBinding = binding: action: { + inherit action; + key = binding.value; + desc = binding.description; + }; + + mkSetLuaLznBinding = binding: action: { + inherit action; + key = binding.value; + lua = true; + desc = binding.description; + }; }; in binds diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 7d24163e..7e4c202b 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.strings) hasPrefix removePrefix; - inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr; + inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int; # Get the names of all flake inputs that start with the given prefix. fromInputs = { @@ -53,6 +53,190 @@ }; borderPresets = ["none" "single" "double" "rounded" "solid" "shadow"]; + luaInline = lib.mkOptionType { + name = "luaInline"; + check = x: lib.nvim.lua.isLuaInline x; + }; + + lznKeysSpec = submodule { + options = { + desc = mkOption { + description = "Description of the key map"; + type = nullOr str; + default = null; + }; + + noremap = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + expr = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + nowait = mkOption { + description = "TBD"; + type = bool; + default = false; + }; + + ft = mkOption { + description = "TBD"; + type = nullOr (listOf str); + default = null; + }; + + key = mkOption { + type = str; + description = "Key to bind to"; + }; + + action = mkOption { + type = nullOr str; + default = null; + description = "Action to trigger."; + }; + + lua = mkOption { + type = bool; + default = false; + description = "If true the action is treated as a lua function instead of a vim command."; + }; + + mode = mkOption { + description = "Modes to bind in"; + type = listOf str; + default = ["n" "x" "s" "o"]; + }; + }; + }; + + lznPluginTableType = attrsOf lznPluginType; + lznPluginType = submodule { + options = { + ## Should probably infer from the actual plugin somehow + ## In general this is the name passed to packadd, so the dir name of the plugin + # name = mkOption { + # type= str; + # } + + # Non-lz.n options + + package = mkOption { + type = pluginType; + description = "Plugin package"; + }; + + setupModule = mkOption { + type = nullOr str; + description = "Lua module to run setup function on."; + default = null; + }; + + setupOpts = mkOption { + type = submodule {freeformType = attrsOf anything;}; + description = "Options to pass to the setup function"; + default = {}; + }; + + # lz.n options + + enabled = mkOption { + type = nullOr (either bool str); + description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; + default = null; + }; + + beforeAll = mkOption { + type = nullOr str; + description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; + default = null; + }; + + before = mkOption { + type = nullOr str; + description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; + default = null; + }; + + after = mkOption { + type = nullOr str; + description = "Lua code to run after plugin is loaded. This will be wrapped in a function."; + default = null; + }; + + event = mkOption { + description = "Lazy-load on event"; + default = null; + type = let + event = submodule { + options = { + event = mkOption { + type = nullOr (either str (listOf str)); + description = "Exact event name"; + example = "BufEnter"; + }; + pattern = mkOption { + type = nullOr (either str (listOf str)); + description = "Event pattern"; + example = "BufEnter *.lua"; + }; + }; + }; + in + nullOr (oneOf [str (listOf str) event]); + }; + + cmd = mkOption { + description = "Lazy-load on command"; + default = null; + type = nullOr (either str (listOf str)); + }; + + ft = mkOption { + description = "Lazy-load on filetype"; + default = null; + type = nullOr (either str (listOf str)); + }; + + keys = mkOption { + description = "Lazy-load on key mapping"; + default = null; + type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); + example = '' + keys = [ + {lhs = "s"; rhs = ":NvimTreeToggle"; desc = "Toggle NvimTree"} + ] + ''; + }; + + colorscheme = mkOption { + description = "Lazy-load on colorscheme."; + type = nullOr (either str (listOf str)); + default = null; + }; + + priority = mkOption { + type = nullOr int; + description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; + default = null; + }; + + load = mkOption { + type = nullOr str; + default = null; + description = '' + Lua code to override the `vim.g.lz_n.load()` function for a single plugin. + + This will be wrapped in a function + ''; + }; + }; + }; in { inherit extraPluginType fromInputs pluginType; From 34ffdaedcd6bf4c6e96ee0eaa84fc08b287a7fb3 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:21 +0200 Subject: [PATCH 06/19] telescope: lazy load --- modules/plugins/utility/telescope/config.nix | 114 +++++++++---------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index 68af9645..f50e955e 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -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 " 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.resume " Telescope resume") + 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 " 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") + cmd = ["Telescope"]; - (mkIf config.vim.lsp.enable (mkMerge [ - (mkSetBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") - (mkSetBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") + keys = + [ + (mkSetLznBinding mappings.findFiles " Telescope find_files") + (mkSetLznBinding mappings.liveGrep " Telescope live_grep") + (mkSetLznBinding mappings.buffers " Telescope buffers") + (mkSetLznBinding mappings.helpTags " Telescope help_tags") + (mkSetLznBinding mappings.open " Telescope") - (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") - ])) + (mkSetLznBinding mappings.gitCommits " Telescope git_commits") + (mkSetLznBinding mappings.gitBufferCommits " Telescope git_bcommits") + (mkSetLznBinding mappings.gitBranches " Telescope git_branches") + (mkSetLznBinding mappings.gitStatus " Telescope git_status") + (mkSetLznBinding mappings.gitStash " Telescope git_stash") + ] + ++ (optionals config.vim.lsp.enable [ + (mkSetLznBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") + (mkSetLznBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") - ( - mkIf config.vim.treesitter.enable - (mkSetBinding mappings.treesitter " Telescope treesitter") - ) - - ( - mkIf config.vim.projects.project-nvim.enable - (mkSetBinding mappings.findProjects " Telescope projects") - ) + (mkSetLznBinding mappings.lspReferences " Telescope lsp_references") + (mkSetLznBinding mappings.lspImplementations " Telescope lsp_implementations") + (mkSetLznBinding mappings.lspDefinitions " Telescope lsp_definitions") + (mkSetLznBinding mappings.lspTypeDefinitions " Telescope lsp_type_definitions") + (mkSetLznBinding mappings.diagnostics " Telescope diagnostics") + ]) + ++ ( + optionals config.vim.treesitter.enable [ + (mkSetLznBinding mappings.treesitter " Telescope treesitter") + ] + ) + ++ ( + optionals config.vim.projects.project-nvim.enable [ + (mkSetLznBinding mappings.findProjects "") + ] + ); + } ]; binds.whichKey.register = pushDownDefault { @@ -66,29 +79,6 @@ in { "fv" = "Telescope Git"; "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 "" - } - ''; }; }; } From 40984ca347f04a5b31de20139e13f71912910147 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:38 +0200 Subject: [PATCH 07/19] nvim-tree: lazy load --- modules/plugins/filetree/nvimtree/config.nix | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index b97b1e45..66a901b5 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -5,10 +5,9 @@ ... }: let inherit (lib.strings) optionalString; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkBinding; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkLznBinding; inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.binds) pushDownDefault; cfg = config.vim.filetree.nvimTree; @@ -16,19 +15,25 @@ inherit (self.options.vim.filetree.nvimTree) mappings; in { config = mkIf cfg.enable { - vim.startPlugins = ["nvim-tree-lua"]; - - vim.maps.normal = mkMerge [ - (mkBinding cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) - (mkBinding cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) - (mkBinding cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) - (mkBinding cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) - ]; - vim.binds.whichKey.register = pushDownDefault { "t" = "+NvimTree"; }; + vim.lazy.plugins = [ + { + package = "nvim-tree-lua"; + setupModule = "nvim-tree"; + inherit (cfg) setupOpts; + cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; + keys = [ + (mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) + (mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) + (mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) + (mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) + ]; + } + ]; + vim.pluginRC.nvimtreelua = entryAnywhere '' ${ optionalString cfg.setupOpts.disable_netrw '' @@ -38,10 +43,9 @@ in { '' } - require'nvim-tree'.setup(${toLuaObject cfg.setupOpts}) - ${ optionalString cfg.openOnSetup '' + ${optionalString config.vim.lazy.enable ''require('lz.n').trigger_load("nvim-tree-lua")''} -- autostart behaviour -- Open on startup has been deprecated -- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup From 8cbe4ac3a8d1e9ea304ecef78334f4d70f7a7184 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:43 +0200 Subject: [PATCH 08/19] dapui: lazy load --- modules/plugins/debugger/nvim-dap/config.nix | 33 +++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index 072ad9af..1c80ac41 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -6,7 +6,7 @@ inherit (lib.strings) optionalString; inherit (lib.modules) mkIf mkMerge; inherit (lib.attrsets) mapAttrs; - inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding; inherit (lib.nvim.dag) entryAnywhere entryAfter; cfg = config.vim.debugger.nvim-dap; @@ -49,24 +49,33 @@ in { ]; }) (mkIf (cfg.enable && cfg.ui.enable) { - vim.startPlugins = ["nvim-dap-ui" "nvim-nio"]; + vim.startPlugins = ["nvim-nio"]; - vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ('' - local dapui = require("dapui") - dapui.setup() - '' - + optionalString cfg.ui.autoStart '' + vim.lazy.plugins = [ + { + package = "nvim-dap-ui"; + setupModule = "dapui"; + setupOpts = {}; + + keys = [ + (mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end") + ]; + } + ]; + + vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ( + optionalString cfg.ui.autoStart '' dap.listeners.after.event_initialized["dapui_config"] = function() - dapui.open() + require("dapui").open() end dap.listeners.before.event_terminated["dapui_config"] = function() - dapui.close() + require("dapui").close() end dap.listeners.before.event_exited["dapui_config"] = function() - dapui.close() + require("dapui").close() end - ''); - vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; + '' + ); }) ]; } From beb9d99e242d6d7c2a15fbec05f1e59726df0a5d Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:48 +0200 Subject: [PATCH 09/19] trouble: lazy load --- modules/plugins/lsp/trouble/config.nix | 33 +++++++++++++------------ modules/plugins/lsp/trouble/trouble.nix | 3 +++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/plugins/lsp/trouble/config.nix b/modules/plugins/lsp/trouble/config.nix index dd853e30..1a7eb468 100644 --- a/modules/plugins/lsp/trouble/config.nix +++ b/modules/plugins/lsp/trouble/config.nix @@ -3,9 +3,8 @@ lib, ... }: let - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault; cfg = config.vim.lsp; @@ -15,15 +14,22 @@ in { config = mkIf (cfg.enable && cfg.trouble.enable) { vim = { - startPlugins = ["trouble"]; + lazy.plugins = [ + { + package = "trouble"; + setupModule = "trouble"; + inherit (cfg.trouble) setupOpts; - maps.normal = mkMerge [ - (mkSetBinding mappings.toggle "TroubleToggle") - (mkSetBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") - (mkSetBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") - (mkSetBinding mappings.lspReferences "TroubleToggle lsp_references") - (mkSetBinding mappings.quickfix "TroubleToggle quickfix") - (mkSetBinding mappings.locList "TroubleToggle loclist") + cmd = "Trouble"; + keys = [ + (mkSetLznBinding mappings.toggle "TroubleToggle") + (mkSetLznBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") + (mkSetLznBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") + (mkSetLznBinding mappings.lspReferences "TroubleToggle lsp_references") + (mkSetLznBinding mappings.quickfix "TroubleToggle quickfix") + (mkSetLznBinding mappings.locList "TroubleToggle loclist") + ]; + } ]; binds.whichKey.register = pushDownDefault { @@ -31,11 +37,6 @@ in { "x" = "+Trouble"; "lw" = "Workspace"; }; - - pluginRC.trouble = entryAnywhere '' - -- Enable trouble diagnostics viewer - require("trouble").setup {} - ''; }; }; } diff --git a/modules/plugins/lsp/trouble/trouble.nix b/modules/plugins/lsp/trouble/trouble.nix index bd16c67e..691cb15a 100644 --- a/modules/plugins/lsp/trouble/trouble.nix +++ b/modules/plugins/lsp/trouble/trouble.nix @@ -1,11 +1,14 @@ {lib, ...}: let inherit (lib.options) mkEnableOption; inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.lsp = { trouble = { enable = mkEnableOption "trouble diagnostics viewer"; + setupOpts = mkPluginSetupOption "Telescope" {}; + mappings = { toggle = mkMappingOption "Toggle trouble [trouble]" "xx"; workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "lwd"; From fcf185fd232eb2ef8de5d19b5eee937796474700 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:54 +0200 Subject: [PATCH 10/19] toggleterm: lazy load --- .../plugins/terminal/toggleterm/config.nix | 76 ++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index 07851e40..e96aec5b 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -4,55 +4,45 @@ ... }: let inherit (builtins) toJSON; - inherit (lib.lists) optionals; - inherit (lib.modules) mkIf mkMerge; + inherit (lib.strings) optionalString; + inherit (lib.modules) mkIf; inherit (lib.meta) getExe; - inherit (lib.nvim.binds) mkBinding; - inherit (lib.nvim.dag) entryAnywhere entryAfter; - inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.binds) mkLznBinding; cfg = config.vim.terminal.toggleterm; in { - config = mkMerge [ - ( - mkIf cfg.enable { - vim = { - startPlugins = [ - "toggleterm-nvim" + config = mkIf cfg.enable { + vim = { + lazy.plugins = [ + { + package = "toggleterm-nvim"; + cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; + keys = [ + (mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal") + {key = cfg.lazygit.mappings.open;} ]; - maps.normal = mkBinding cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal"; + setupModule = "toggleterm"; + inherit (cfg) setupOpts; + after = optionalString cfg.lazygit.enable '' + local terminal = require 'toggleterm.terminal' + local lazygit = terminal.Terminal:new({ + cmd = '${ + if (cfg.lazygit.package != null) + then getExe cfg.lazygit.package + else "lazygit" + }', + direction = '${cfg.lazygit.direction}', + hidden = true, + on_open = function(term) + vim.cmd("startinsert!") + end + }) - pluginRC.toggleterm = entryAnywhere '' - require("toggleterm").setup(${toLuaObject cfg.setupOpts}) + vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) ''; - }; - } - ) - ( - mkIf (cfg.enable && cfg.lazygit.enable) - { - vim.startPlugins = optionals (cfg.lazygit.package != null) [ - cfg.lazygit.package - ]; - vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] '' - local terminal = require 'toggleterm.terminal' - local lazygit = terminal.Terminal:new({ - cmd = '${ - if (cfg.lazygit.package != null) - then getExe cfg.lazygit.package - else "lazygit" - }', - direction = '${cfg.lazygit.direction}', - hidden = true, - on_open = function(term) - vim.cmd("startinsert!") - end - }) - - vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) - ''; - } - ) - ]; + } + ]; + }; + }; } From ebc5426b786a32f3f861c81b3fa4cfee57ea9114 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:59:00 +0200 Subject: [PATCH 11/19] cheatsheet: lazy load --- .../plugins/utility/binds/cheatsheet/config.nix | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/plugins/utility/binds/cheatsheet/config.nix b/modules/plugins/utility/binds/cheatsheet/config.nix index 2848ddc2..f7bfa44d 100644 --- a/modules/plugins/utility/binds/cheatsheet/config.nix +++ b/modules/plugins/utility/binds/cheatsheet/config.nix @@ -4,15 +4,20 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.strings) optionalString; cfg = config.vim.binds.cheatsheet; in { config = mkIf cfg.enable { - vim.startPlugins = ["cheatsheet-nvim"]; + vim.lazy.plugins = [ + { + package = "cheatsheet-nvim"; + setupModule = "cheatsheet"; + setupOpts = {}; + cmd = ["Cheatsheet" "CheatsheetEdit"]; - vim.pluginRC.cheaetsheet-nvim = entryAnywhere '' - require('cheatsheet').setup({}) - ''; + before = optionalString config.vim.lazy.enable "require('lz.n').trigger_load('telescope')"; + } + ]; }; } From e764f1fdf56ba981d262ddc5a69cf8fe0a356eab Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:59:05 +0200 Subject: [PATCH 12/19] diffview: lazy load --- modules/plugins/utility/diffview/config.nix | 15 +++++++++++---- modules/plugins/utility/diffview/diffview.nix | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/plugins/utility/diffview/config.nix b/modules/plugins/utility/diffview/config.nix index 681a3053..5ea51d78 100644 --- a/modules/plugins/utility/diffview/config.nix +++ b/modules/plugins/utility/diffview/config.nix @@ -8,9 +8,16 @@ cfg = config.vim.utility.diffview-nvim; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "diffview-nvim" - "plenary-nvim" - ]; + vim = { + startPlugins = ["plenary-nvim"]; + lazy.plugins = [ + { + package = "diffview-nvim"; + cmd = ["DiffviewClose" "DiffviewFileHistory" "DiffviewFocusFiles" "DiffviewLog" "DiffviewOpen" "DiffviewRefresh" "DiffviewToggleFiles"]; + setupModule = "diffview"; + inherit (cfg) setupOpts; + } + ]; + }; }; } diff --git a/modules/plugins/utility/diffview/diffview.nix b/modules/plugins/utility/diffview/diffview.nix index 74ddd574..793666dc 100644 --- a/modules/plugins/utility/diffview/diffview.nix +++ b/modules/plugins/utility/diffview/diffview.nix @@ -1,7 +1,9 @@ {lib, ...}: let inherit (lib.options) mkEnableOption; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.utility.diffview-nvim = { enable = mkEnableOption "diffview-nvim: cycle through diffs for all modified files for any git rev"; + setupOpts = mkPluginSetupOption "Fidget" {}; }; } From a17b1e0fa73198608b121027700067a70cdc8667 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:59:10 +0200 Subject: [PATCH 13/19] icon-picker: lazy load --- .../plugins/utility/icon-picker/config.nix | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/plugins/utility/icon-picker/config.nix b/modules/plugins/utility/icon-picker/config.nix index 405f6917..13fa45e6 100644 --- a/modules/plugins/utility/icon-picker/config.nix +++ b/modules/plugins/utility/icon-picker/config.nix @@ -4,20 +4,22 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.utility.icon-picker; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "icon-picker-nvim" - "dressing-nvim" - ]; + vim.startPlugins = ["dressing-nvim"]; - vim.pluginRC.icon-picker = entryAnywhere '' - require("icon-picker").setup({ - disable_legacy_commands = true - }) - ''; + vim.lazy.plugins = [ + { + package = "icon-picker-nvim"; + setupModule = "icon-picker"; + setupOpts = { + disable_legacy_commands = true; + }; + + cmd = ["IconPickerInsert" "IconPickerNormal" "IconPickerYank"]; + } + ]; }; } From 9a47b6f83d1a66de973385102369d7023ab2cde4 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:59:14 +0200 Subject: [PATCH 14/19] leap: lazy load --- .../plugins/utility/motion/leap/config.nix | 110 ++++++++---------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/modules/plugins/utility/motion/leap/config.nix b/modules/plugins/utility/motion/leap/config.nix index 9ede98f3..9e9cf40e 100644 --- a/modules/plugins/utility/motion/leap/config.nix +++ b/modules/plugins/utility/motion/leap/config.nix @@ -3,71 +3,59 @@ lib, ... }: let - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkBinding; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkLznBinding; cfg = config.vim.utility.motion.leap; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "leap-nvim" - "vim-repeat" - ]; + vim = { + startPlugins = ["vim-repeat"]; + lazy.plugins = [ + { + package = "leap-nvim"; + keys = [ + (mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTo "(leap-forward-to)" "Leap forward to") + (mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTo "(leap-backward-to)" "Leap backward to") + (mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTill "(leap-forward-till)" "Leap forward till") + (mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTill "(leap-backward-till)" "Leap backward till") + (mkLznBinding ["n" "o" "x"] cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") + ]; - vim.maps.normal = mkMerge [ - (mkBinding cfg.mappings.leapForwardTo "(leap-forward-to)" "Leap forward to") - (mkBinding cfg.mappings.leapBackwardTo "(leap-backward-to)" "Leap backward to") - (mkBinding cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") - ]; - - vim.maps.operator = mkMerge [ - (mkBinding cfg.mappings.leapForwardTo "(leap-forward-to)" "Leap forward to") - (mkBinding cfg.mappings.leapBackwardTo "(leap-backward-to)" "Leap backward to") - (mkBinding cfg.mappings.leapForwardTill "(leap-forward-till)" "Leap forward till") - (mkBinding cfg.mappings.leapBackwardTill "(leap-backward-till)" "Leap backward till") - (mkBinding cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") - ]; - - vim.maps.visualOnly = mkMerge [ - (mkBinding cfg.mappings.leapForwardTo "(leap-forward-to)" "Leap forward to") - (mkBinding cfg.mappings.leapBackwardTo "(leap-backward-to)" "Leap backward to") - (mkBinding cfg.mappings.leapForwardTill "(leap-forward-till)" "Leap forward till") - (mkBinding cfg.mappings.leapBackwardTill "(leap-backward-till)" "Leap backward till") - (mkBinding cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") - ]; - - vim.pluginRC.leap-nvim = entryAnywhere '' - require('leap').opts = { - max_phase_one_targets = nil, - highlight_unlabeled_phase_one_targets = false, - max_highlighted_traversal_targets = 10, - case_sensitive = false, - equivalence_classes = { ' \t\r\n', }, - substitute_chars = {}, - safe_labels = { - "s", "f", "n", "u", "t", "/", - "S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z" - }, - labels = { - "s", "f", "n", - "j", "k", "l", "h", "o", "d", "w", "e", "m", "b", - "u", "y", "v", "r", "g", "t", "c", "x", "/", "z", - "S", "F", "N", - "J", "K", "L", "H", "O", "D", "W", "E", "M", "B", - "U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z" - }, - special_keys = { - repeat_search = '', - next_phase_one_target = '', - next_target = {'', ';'}, - prev_target = {'', ','}, - next_group = '', - prev_group = '', - multi_accept = '', - multi_revert = '', - }, - } - ''; + after = '' + require('leap').opts = { + max_phase_one_targets = nil, + highlight_unlabeled_phase_one_targets = false, + max_highlighted_traversal_targets = 10, + case_sensitive = false, + equivalence_classes = { ' \t\r\n', }, + substitute_chars = {}, + safe_labels = { + "s", "f", "n", "u", "t", "/", + "S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z" + }, + labels = { + "s", "f", "n", + "j", "k", "l", "h", "o", "d", "w", "e", "m", "b", + "u", "y", "v", "r", "g", "t", "c", "x", "/", "z", + "S", "F", "N", + "J", "K", "L", "H", "O", "D", "W", "E", "M", "B", + "U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z" + }, + special_keys = { + repeat_search = '', + next_phase_one_target = '', + next_target = {'', ';'}, + prev_target = {'', ','}, + next_group = '', + prev_group = '', + multi_accept = '', + multi_revert = '', + }, + } + ''; + } + ]; + }; }; } From 2f281cf07a9693ddc45fc63675dc7219fbc95073 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:59:19 +0200 Subject: [PATCH 15/19] fidget: lazy load --- modules/plugins/visuals/fidget/config.nix | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/plugins/visuals/fidget/config.nix b/modules/plugins/visuals/fidget/config.nix index 3ae3b6b9..ef2544ec 100644 --- a/modules/plugins/visuals/fidget/config.nix +++ b/modules/plugins/visuals/fidget/config.nix @@ -4,16 +4,19 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.visuals.fidget-nvim; in { config = mkIf cfg.enable { - vim.startPlugins = ["fidget-nvim"]; - - vim.pluginRC.fidget-nvim = entryAnywhere '' - require'fidget'.setup(${toLuaObject cfg.setupOpts}) - ''; + vim.lazy = { + plugins = [ + { + package = "fidget-nvim"; + setupModule = "fidget"; + event = "LspAttach"; + inherit (cfg) setupOpts; + } + ]; + }; }; } From e6df7c6aa79dc59572f69baa1d10b0faa19b8b91 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 6 Oct 2024 14:59:06 +0200 Subject: [PATCH 16/19] fixup! lib.binds: add lz.n variant of bind functions --- lib/types/plugins.nix | 186 +----------------------------------------- 1 file changed, 1 insertion(+), 185 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 7e4c202b..7d24163e 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.strings) hasPrefix removePrefix; - inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int; + inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr; # Get the names of all flake inputs that start with the given prefix. fromInputs = { @@ -53,190 +53,6 @@ }; borderPresets = ["none" "single" "double" "rounded" "solid" "shadow"]; - luaInline = lib.mkOptionType { - name = "luaInline"; - check = x: lib.nvim.lua.isLuaInline x; - }; - - lznKeysSpec = submodule { - options = { - desc = mkOption { - description = "Description of the key map"; - type = nullOr str; - default = null; - }; - - noremap = mkOption { - description = "TBD"; - type = bool; - default = false; - }; - - expr = mkOption { - description = "TBD"; - type = bool; - default = false; - }; - - nowait = mkOption { - description = "TBD"; - type = bool; - default = false; - }; - - ft = mkOption { - description = "TBD"; - type = nullOr (listOf str); - default = null; - }; - - key = mkOption { - type = str; - description = "Key to bind to"; - }; - - action = mkOption { - type = nullOr str; - default = null; - description = "Action to trigger."; - }; - - lua = mkOption { - type = bool; - default = false; - description = "If true the action is treated as a lua function instead of a vim command."; - }; - - mode = mkOption { - description = "Modes to bind in"; - type = listOf str; - default = ["n" "x" "s" "o"]; - }; - }; - }; - - lznPluginTableType = attrsOf lznPluginType; - lznPluginType = submodule { - options = { - ## Should probably infer from the actual plugin somehow - ## In general this is the name passed to packadd, so the dir name of the plugin - # name = mkOption { - # type= str; - # } - - # Non-lz.n options - - package = mkOption { - type = pluginType; - description = "Plugin package"; - }; - - setupModule = mkOption { - type = nullOr str; - description = "Lua module to run setup function on."; - default = null; - }; - - setupOpts = mkOption { - type = submodule {freeformType = attrsOf anything;}; - description = "Options to pass to the setup function"; - default = {}; - }; - - # lz.n options - - enabled = mkOption { - type = nullOr (either bool str); - description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; - default = null; - }; - - beforeAll = mkOption { - type = nullOr str; - description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; - default = null; - }; - - before = mkOption { - type = nullOr str; - description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; - default = null; - }; - - after = mkOption { - type = nullOr str; - description = "Lua code to run after plugin is loaded. This will be wrapped in a function."; - default = null; - }; - - event = mkOption { - description = "Lazy-load on event"; - default = null; - type = let - event = submodule { - options = { - event = mkOption { - type = nullOr (either str (listOf str)); - description = "Exact event name"; - example = "BufEnter"; - }; - pattern = mkOption { - type = nullOr (either str (listOf str)); - description = "Event pattern"; - example = "BufEnter *.lua"; - }; - }; - }; - in - nullOr (oneOf [str (listOf str) event]); - }; - - cmd = mkOption { - description = "Lazy-load on command"; - default = null; - type = nullOr (either str (listOf str)); - }; - - ft = mkOption { - description = "Lazy-load on filetype"; - default = null; - type = nullOr (either str (listOf str)); - }; - - keys = mkOption { - description = "Lazy-load on key mapping"; - default = null; - type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); - example = '' - keys = [ - {lhs = "s"; rhs = ":NvimTreeToggle"; desc = "Toggle NvimTree"} - ] - ''; - }; - - colorscheme = mkOption { - description = "Lazy-load on colorscheme."; - type = nullOr (either str (listOf str)); - default = null; - }; - - priority = mkOption { - type = nullOr int; - description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; - default = null; - }; - - load = mkOption { - type = nullOr str; - default = null; - description = '' - Lua code to override the `vim.g.lz_n.load()` function for a single plugin. - - This will be wrapped in a function - ''; - }; - }; - }; in { inherit extraPluginType fromInputs pluginType; From 9a56cc3b8f231d15e68a07d3e000b64706e9bb0a Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 6 Oct 2024 15:02:31 +0200 Subject: [PATCH 17/19] fixup! trouble: lazy load --- modules/plugins/lsp/trouble/trouble.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/lsp/trouble/trouble.nix b/modules/plugins/lsp/trouble/trouble.nix index 691cb15a..04bd5068 100644 --- a/modules/plugins/lsp/trouble/trouble.nix +++ b/modules/plugins/lsp/trouble/trouble.nix @@ -7,7 +7,7 @@ in { trouble = { enable = mkEnableOption "trouble diagnostics viewer"; - setupOpts = mkPluginSetupOption "Telescope" {}; + setupOpts = mkPluginSetupOption "Trouble" {}; mappings = { toggle = mkMappingOption "Toggle trouble [trouble]" "xx"; From d5b5c5294cc2790b8db43c9f0402e061ccba3f32 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 6 Oct 2024 15:09:10 +0200 Subject: [PATCH 18/19] fixup! toggleterm: lazy load --- modules/plugins/terminal/toggleterm/config.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index e96aec5b..b4167489 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -10,6 +10,7 @@ inherit (lib.nvim.binds) mkLznBinding; cfg = config.vim.terminal.toggleterm; + lazygitMapDesc = "Open lazygit [toggleterm]"; in { config = mkIf cfg.enable { vim = { @@ -19,7 +20,10 @@ in { cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; keys = [ (mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal") - {key = cfg.lazygit.mappings.open;} + { + key = cfg.lazygit.mappings.open; + desc = lazygitMapDesc; + } ]; setupModule = "toggleterm"; @@ -39,7 +43,7 @@ in { end }) - vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) + vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) ''; } ]; From 887144f8964a48524a2cdde0baa4247e027bab62 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 6 Oct 2024 15:17:28 +0200 Subject: [PATCH 19/19] fixup! fidget: lazy load --- modules/plugins/visuals/fidget/config.nix | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/plugins/visuals/fidget/config.nix b/modules/plugins/visuals/fidget/config.nix index ef2544ec..6e81e9d6 100644 --- a/modules/plugins/visuals/fidget/config.nix +++ b/modules/plugins/visuals/fidget/config.nix @@ -8,15 +8,13 @@ cfg = config.vim.visuals.fidget-nvim; in { config = mkIf cfg.enable { - vim.lazy = { - plugins = [ - { - package = "fidget-nvim"; - setupModule = "fidget"; - event = "LspAttach"; - inherit (cfg) setupOpts; - } - ]; - }; + vim.lazy.plugins = [ + { + package = "fidget-nvim"; + setupModule = "fidget"; + event = "LspAttach"; + inherit (cfg) setupOpts; + } + ]; }; }