From b636b220469f236e987de3c68436f121c0e81a79 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 21 Oct 2024 20:19:18 +0200 Subject: [PATCH 1/9] copilot: lazy load --- modules/plugins/assistant/copilot/config.nix | 115 ++++++++++--------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 923a0c6d..6576d505 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -4,11 +4,7 @@ ... }: let inherit (builtins) toJSON; - inherit (lib.nvim.lua) toLuaObject; - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.lists) optionals; - inherit (lib.nvim.binds) mkLuaBinding; + inherit (lib.modules) mkIf; cfg = config.vim.assistant.copilot; @@ -23,65 +19,70 @@ end end ''; + + mkLuaKeymap = mode: key: action: desc: opts: + opts + // { + inherit mode key action desc; + lua = true; + }; in { config = mkIf cfg.enable { - vim.startPlugins = - [ - "copilot-lua" - # cfg.copilotNodePackage - ] - ++ optionals cfg.cmp.enable [ - "copilot-cmp" - ]; + vim = { + lazy.plugins = { + copilot-lua = { + package = "copilot-lua"; + setupModule = "copilot"; + inherit (cfg) setupOpts; + after = mkIf cfg.cmp.enable "require('copilot_cmp').setup()"; - vim.autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";}; + cmd = ["Copilot" "CopilotAuth" "CopilotDetach" "CopilotPanel" "CopilotStop"]; + keys = [ + (mkLuaKeymap ["n"] cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion" {}) + (mkLuaKeymap ["n"] cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion" {}) + (mkLuaKeymap ["n"] cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion" {}) + (mkLuaKeymap ["n"] cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion" {}) + (mkLuaKeymap ["n"] cfg.mappings.panel.open (wrapPanelBinding '' + function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end + '' + cfg.mappings.panel.open) "[copilot] Accept suggestion" {}) - vim.pluginRC.copilot = entryAnywhere '' - require("copilot").setup(${toLuaObject cfg.setupOpts}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.accept "function() require('copilot.suggestion').accept() end" "[copilot] Accept suggestion" {}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptLine "function() require('copilot.suggestion').accept_line() end" "[copilot] Accept suggestion (line)" {}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptWord "function() require('copilot.suggestion').accept_word() end" "[copilot] Accept suggestion (word)" {}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.dismiss "function() require('copilot.suggestion').dismiss() end" "[copilot] dismiss suggestion" {}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.next "function() require('copilot.suggestion').next() end" "[copilot] next suggestion" {}) + (mkLuaKeymap ["i"] cfg.mappings.suggestion.prev "function() require('copilot.suggestion').prev() end" "[copilot] previous suggestion" {}) + ]; + }; - ${lib.optionalString cfg.cmp.enable '' - require("copilot_cmp").setup() - ''} - ''; - - # Disable plugin handled keymaps. - # Setting it here so that it doesn't show up in user docs - vim.assistant.copilot.setupOpts = { - panel.keymap = { - jump_prev = lib.mkDefault false; - jump_next = lib.mkDefault false; - accept = lib.mkDefault false; - refresh = lib.mkDefault false; - open = lib.mkDefault false; + copilot-cmp = mkIf cfg.cmp.enable { + package = "copilot-cmp"; + lazy = true; + }; }; - suggestion.keymap = { - accept = lib.mkDefault false; - accept_word = lib.mkDefault false; - accept_line = lib.mkDefault false; - next = lib.mkDefault false; - prev = lib.mkDefault false; - dismiss = lib.mkDefault false; + + autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";}; + + # Disable plugin handled keymaps. + # Setting it here so that it doesn't show up in user docs + assistant.copilot.setupOpts = { + panel.keymap = { + jump_prev = lib.mkDefault false; + jump_next = lib.mkDefault false; + accept = lib.mkDefault false; + refresh = lib.mkDefault false; + open = lib.mkDefault false; + }; + suggestion.keymap = { + accept = lib.mkDefault false; + accept_word = lib.mkDefault false; + accept_line = lib.mkDefault false; + next = lib.mkDefault false; + prev = lib.mkDefault false; + dismiss = lib.mkDefault false; + }; }; }; - - vim.maps.normal = mkMerge [ - (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding '' - function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end - '' - cfg.mappings.panel.open) "[copilot] Accept suggestion") - ]; - - vim.maps.insert = mkMerge [ - (mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)") - (mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)") - (mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion") - (mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion") - (mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion") - ]; }; } From 46a1f0427f15bace8ac0003580087b193efe3121 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 21 Oct 2024 18:25:42 +0200 Subject: [PATCH 2/9] cmp: lazy load this moves cmp itself to lazy.plugins but other plugins that call cmp are not yet lazy so cmp is technically not yet lazy --- .../plugins/completion/nvim-cmp/config.nix | 139 ++++++++++-------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 5d20242d..9587f807 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -6,7 +6,6 @@ inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.lua) toLuaObject; inherit (builtins) attrNames; @@ -16,78 +15,92 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = [ - "nvim-cmp" - "cmp-buffer" - "cmp-path" - ]; + lazy.plugins = { + # cmp sources are loaded via lzn-auto-require as long as it is defined + # in cmp sources + cmp-buffer = { + package = "cmp-buffer"; + lazy = true; + }; + cmp-path = { + package = "cmp-path"; + lazy = true; + }; + nvim-cmp = { + package = "nvim-cmp"; + after = '' + ${optionalString luasnipEnable "local luasnip = require('luasnip')"} + local cmp = require("cmp") + cmp.setup(${toLuaObject cfg.setupOpts}) + ''; - autocomplete.nvim-cmp.sources = { - nvim-cmp = null; - buffer = "[Buffer]"; - path = "[Path]"; + event = ["InsertEnter" "CmdlineEnter"]; + lazy = true; + }; }; - autocomplete.nvim-cmp.setupOpts = { - sources = map (s: {name = s;}) (attrNames cfg.sources); - - # TODO: try to get nvim-cmp to follow global border style - window = mkIf config.vim.ui.borders.enable { - completion = mkLuaInline "cmp.config.window.bordered()"; - documentation = mkLuaInline "cmp.config.window.bordered()"; + autocomplete.nvim-cmp = { + sources = { + nvim-cmp = null; + buffer = "[Buffer]"; + path = "[Path]"; }; - formatting.format = cfg.format; - }; + setupOpts = { + sources = map (s: {name = s;}) (attrNames cfg.sources); - pluginRC.nvim-cmp = mkIf cfg.enable (entryAfter ["autopairs" "luasnip"] '' - ${optionalString luasnipEnable "local luasnip = require('luasnip')"} - local cmp = require("cmp") - cmp.setup(${toLuaObject cfg.setupOpts}) - ''); + # TODO: try to get nvim-cmp to follow global border style + window = mkIf config.vim.ui.borders.enable { + completion = mkLuaInline "cmp.config.window.bordered()"; + documentation = mkLuaInline "cmp.config.window.bordered()"; + }; - # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section - autocomplete.nvim-cmp.setupOpts.mapping = { - ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; - ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; - ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; - ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; - ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; + formatting.format = cfg.format; + }; - ${mappings.next} = mkLuaInline '' - cmp.mapping(function(fallback) - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end + # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section + setupOpts.mapping = { + ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; + ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; + ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; + ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; + ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; - if cmp.visible() then - cmp.select_next_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(1) then - luasnip.jump(1) - ''} - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end) - ''; + ${mappings.next} = mkLuaInline '' + cmp.mapping(function(fallback) + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end - ${mappings.previous} = mkLuaInline '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - ''} - else - fallback() - end - end) - ''; + if cmp.visible() then + cmp.select_next_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(1) then + luasnip.jump(1) + ''} + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end) + ''; + + ${mappings.previous} = mkLuaInline '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + ''} + else + fallback() + end + end) + ''; + }; }; }; }; From e829a0964ac8a30d3b31c25a7d0ce2bed3761f59 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 21 Oct 2024 18:42:02 +0200 Subject: [PATCH 3/9] luasnip: lazy load --- modules/plugins/snippets/luasnip/config.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/plugins/snippets/luasnip/config.nix b/modules/plugins/snippets/luasnip/config.nix index 541fd0fd..57a3c54a 100644 --- a/modules/plugins/snippets/luasnip/config.nix +++ b/modules/plugins/snippets/luasnip/config.nix @@ -9,9 +9,19 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = ["luasnip" "cmp-luasnip"] ++ cfg.providers; + lazy.plugins = { + luasnip = { + package = "luasnip"; + lazy = true; + after = cfg.loaders; + }; + cmp-luasnip = mkIf config.vim.autocomplete.nvim-cmp.enable { + package = "cmp-luasnip"; + lazy = true; + }; + }; + startPlugins = cfg.providers; autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";}; - pluginRC.luasnip = cfg.loaders; }; }; } From f107cc45eb97fb897e5a221b5b4b22cd23453db3 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 13:00:48 +0200 Subject: [PATCH 4/9] flake: add rtp.nvim --- flake.lock | 17 +++++++++++++++++ flake.nix | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/flake.lock b/flake.lock index 5b643b08..2d73a3ed 100644 --- a/flake.lock +++ b/flake.lock @@ -1630,6 +1630,22 @@ "type": "github" } }, + "plugin-rtp-nvim": { + "flake": false, + "locked": { + "lastModified": 1724409589, + "narHash": "sha256-lmJbiD7I7MTEEpukESs67uAmLyn+p66hrUKLbEHp0Kw=", + "owner": "nvim-neorocks", + "repo": "rtp.nvim", + "rev": "494ddfc888bb466555d90ace731856de1320fe45", + "type": "github" + }, + "original": { + "owner": "nvim-neorocks", + "repo": "rtp.nvim", + "type": "github" + } + }, "plugin-rustaceanvim": { "flake": false, "locked": { @@ -2038,6 +2054,7 @@ "plugin-project-nvim": "plugin-project-nvim", "plugin-registers": "plugin-registers", "plugin-rose-pine": "plugin-rose-pine", + "plugin-rtp-nvim": "plugin-rtp-nvim", "plugin-rustaceanvim": "plugin-rustaceanvim", "plugin-scrollbar-nvim": "plugin-scrollbar-nvim", "plugin-smartcolumn": "plugin-smartcolumn", diff --git a/flake.nix b/flake.nix index 40043588..4de493e7 100644 --- a/flake.nix +++ b/flake.nix @@ -124,6 +124,11 @@ flake = false; }; + plugin-rtp-nvim = { + url = "github:nvim-neorocks/rtp.nvim"; + flake = false; + }; + # LSP plugins plugin-nvim-lspconfig = { url = "github:neovim/nvim-lspconfig"; From 4b703964e14f942ea021f747281021f0fbd4c71b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 15:14:15 +0200 Subject: [PATCH 5/9] cmp: actually lazy load source --- modules/plugins/assistant/copilot/config.nix | 8 ++++++++ modules/plugins/completion/nvim-cmp/config.nix | 16 ++++++++++++++++ modules/plugins/snippets/luasnip/config.nix | 8 ++++++++ modules/plugins/treesitter/config.nix | 11 +++++++++++ 4 files changed, 43 insertions(+) diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 6576d505..9c337148 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -5,6 +5,7 @@ }: let inherit (builtins) toJSON; inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; cfg = config.vim.assistant.copilot; @@ -59,7 +60,14 @@ in { copilot-cmp = mkIf cfg.cmp.enable { package = "copilot-cmp"; lazy = true; + after = optionalString config.vim.lazy.enable '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/copilot-cmp') + require("rtp_nvim").source_after_plugin_dir(path) + require("lz.n").trigger_load("copilot-lua") + ''; }; + + nvim-cmp.after = mkIf cfg.cmp.enable "require('lz.n').trigger_load('copilot-cmp')"; }; autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";}; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 9587f807..458b9e99 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -15,23 +15,39 @@ in { config = mkIf cfg.enable { vim = { + startPlugins = ["rtp-nvim"]; lazy.plugins = { # cmp sources are loaded via lzn-auto-require as long as it is defined # in cmp sources cmp-buffer = { package = "cmp-buffer"; lazy = true; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-buffer') + require("rtp_nvim").source_after_plugin_dir(path) + ''; }; cmp-path = { package = "cmp-path"; lazy = true; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-path') + require("rtp_nvim").source_after_plugin_dir(path) + ''; }; nvim-cmp = { package = "nvim-cmp"; after = '' ${optionalString luasnipEnable "local luasnip = require('luasnip')"} + require("lz.n").trigger_load("cmp-path") local cmp = require("cmp") cmp.setup(${toLuaObject cfg.setupOpts}) + + ${ + optionalString config.vim.lazy.enable '' + require("lz.n").trigger_load("cmp-buffer") + '' + } ''; event = ["InsertEnter" "CmdlineEnter"]; diff --git a/modules/plugins/snippets/luasnip/config.nix b/modules/plugins/snippets/luasnip/config.nix index 57a3c54a..4fbbd2cd 100644 --- a/modules/plugins/snippets/luasnip/config.nix +++ b/modules/plugins/snippets/luasnip/config.nix @@ -4,6 +4,7 @@ ... }: let inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; cfg = config.vim.snippets.luasnip; in { @@ -18,7 +19,14 @@ in { cmp-luasnip = mkIf config.vim.autocomplete.nvim-cmp.enable { package = "cmp-luasnip"; lazy = true; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-luasnip') + require("rtp_nvim").source_after_plugin_dir(path) + ''; }; + nvim-cmp.after = optionalString config.vim.lazy.enable '' + require("lz.n").trigger_load("cmp-luasnip") + ''; }; startPlugins = cfg.providers; autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";}; diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index ae093862..584a5451 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -21,6 +21,17 @@ in { vim = { startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter"; + lazy.plugins = { + cmp-treesitter = mkIf usingNvimCmp { + package = "cmp-treesitter"; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-treesitter') + require("rtp_nvim").source_after_plugin_dir(path) + ''; + }; + nvim-cmp.after = mkIf cfg.cmp.enable "require('lz.n').trigger_load('cmp-treesitter')"; + }; + autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";}; treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; From 2f502f17902f4a997d3db37459bf354e3c34f52b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 15:25:59 +0200 Subject: [PATCH 6/9] fixup! cmp: actually lazy load source --- modules/plugins/completion/nvim-cmp/config.nix | 1 - modules/plugins/treesitter/config.nix | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 458b9e99..9140b05f 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -51,7 +51,6 @@ in { ''; event = ["InsertEnter" "CmdlineEnter"]; - lazy = true; }; }; diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 584a5451..e810d7e5 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -19,7 +19,7 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter"; + startPlugins = ["nvim-treesitter"]; lazy.plugins = { cmp-treesitter = mkIf usingNvimCmp { @@ -29,7 +29,7 @@ in { require("rtp_nvim").source_after_plugin_dir(path) ''; }; - nvim-cmp.after = mkIf cfg.cmp.enable "require('lz.n').trigger_load('cmp-treesitter')"; + nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-treesitter')"; }; autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";}; From 1952f41632b3abd71f85518733eb98f9146d1df0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 15:31:11 +0200 Subject: [PATCH 7/9] format --- modules/wrapper/lazy/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 30f9626c..da5dd8c1 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -86,7 +86,7 @@ in { require('lz.n').load(${toLuaObject lznSpecs}) ''; }) - + (mkIf (!cfg.enable) { startPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins; luaConfigPre = From 6664304f7e77d2b3a8b5caf345b73ac4e5543f31 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 15:32:57 +0200 Subject: [PATCH 8/9] docs: fix broken link --- modules/wrapper/lazy/lazy.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index 52ed9c3f..e16a8aa2 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -92,7 +92,7 @@ description = '' Lua code to run after plugin is loaded. This will be wrapped in a function. - If [](#opt-vim.lazy.plugins._.setupModule) is provided, the setup will be ran before `after`. + If [](#opt-vim.lazy.plugins._name_.setupModule) is provided, the setup will be ran before `after`. ''; default = null; }; From 70e988bb33551cc1bbd5bc1b2112f0f45cd28f86 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 22 Oct 2024 15:33:18 +0200 Subject: [PATCH 9/9] cmp-nvim-lsp: lazy load --- modules/plugins/lsp/config.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 52dc15b4..63c21d5a 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -23,7 +23,17 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; + lazy.plugins = { + cmp-nvim-lsp = { + package = "cmp-nvim-lsp"; + lazy = true; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-treesitter') + require("rtp_nvim").source_after_plugin_dir(path) + ''; + }; + nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-nvim-lsp')"; + }; autocomplete.nvim-cmp.sources = {nvim_lsp = "[LSP]";};