From f8625f35f03a2a8a1ea7bf0b09f29d5ac7c07a08 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 15 Aug 2024 08:23:16 +0200 Subject: [PATCH] nvim: Only load plugin spec if plugin files exist Before we load the lazy spec from the 'lua/plugins' directory, we check that the directory exists and contains at least one .lua file. We do not check that the file returns a valid spec but that is just assumed in this case. --- nvim/.config/nvim/lua/core/lazy.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nvim/.config/nvim/lua/core/lazy.lua b/nvim/.config/nvim/lua/core/lazy.lua index f57bf7b..ddb750b 100644 --- a/nvim/.config/nvim/lua/core/lazy.lua +++ b/nvim/.config/nvim/lua/core/lazy.lua @@ -31,8 +31,13 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) +-- ensure plugins specs exist before loading into lazy +local spec_dir = vim.fn.stdpath("config") .. "/lua/plugins" +local spec_exist = (vim.fn.isdirectory(spec_dir) ~= 0) and (#vim.fn.glob(spec_dir .. "/*.lua", nil, true) ~= 0) +local spec = spec_exist and { import = "plugins" } or {} + require("lazy").setup({ - spec = { { import = "plugins" } }, + spec = { spec }, defaults = { lazy = true, version = "*" }, performance = { rtp = { disabled_plugins = { "netrw", "netrwPlugin" } },