Skip to content

Commit

Permalink
fix(loader): prevent loading plugins when loading specs
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 11, 2023
1 parent 9d494e0 commit e1cd9cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/lazy/core/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,21 @@ end
function M.check_autoload(modname, modpath)
local start = uv.hrtime()
M.stats.autoload.total = M.stats.autoload.total + 1

-- check plugins. Again fast, since we check the plugin name from the path.
-- only needed when the plugin mod has been loaded
---@type LazyCorePlugin
local Plugin = package.loaded["lazy.core.plugin"]
if Plugin then
if Plugin and not Plugin.loading then
local plugin = Plugin.find(modpath)
if plugin and modpath:find(plugin.dir, 1, true) == 1 then
-- we're not interested in loader time, so calculate delta here
M.stats.autoload.time = M.stats.autoload.time + uv.hrtime() - start
-- only autoload when plugins have been loaded
if not vim.tbl_isempty(require("lazy.core.config").plugins) then
if not plugin._.loaded then
if plugin.module == false then
error("Plugin " .. plugin.name .. " is not loaded and is configured with module=false")
end
require("lazy.core.loader").load(plugin, { require = modname })
if not plugin._.loaded then
if plugin.module == false then
error("Plugin " .. plugin.name .. " is not loaded and is configured with module=false")
end
require("lazy.core.loader").load(plugin, { require = modname })
end
return true
end
Expand Down
3 changes: 3 additions & 0 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local Cache = require("lazy.core.cache")

---@class LazyCorePlugin
local M = {}
M.loading = false

local list_merge = { "dependencies" }
vim.list_extend(list_merge, vim.tbl_values(Handler.types))
Expand Down Expand Up @@ -330,6 +331,7 @@ function M.update_state()
end

function M.load()
M.loading = true
-- load specs
Util.track("spec")
Config.spec = Spec.new()
Expand Down Expand Up @@ -363,6 +365,7 @@ function M.load()
M.update_state()
Util.track()
require("lazy.core.cache").indexed_unloaded = false
M.loading = false
end

-- Finds the plugin that has this path
Expand Down

0 comments on commit e1cd9cd

Please sign in to comment.