From 2756a6f756758d62eeb4cac64d8c5efbc8878cd1 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Dec 2022 18:46:43 +0100 Subject: [PATCH] fix!: run `init()` before loading start plugins. Fixes #107 --- README.md | 8 +++--- lua/lazy/core/loader.lua | 60 ++++++++++++++++++++-------------------- lua/lazy/core/plugin.lua | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index fca7a0c..a3da113 100644 --- a/README.md +++ b/README.md @@ -511,10 +511,10 @@ startup sequence for more flexibility and better performance. In practice this means that step 10 of [Neovim Initialization](https://neovim.io/doc/user/starting.html#initialization) is done by Lazy: -1. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet) -2. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`) -3. all `/after/plugin` files are sourced (this inludes `/after` from plugins) -4. all the plugins' `init()` functions are executed +1. all the plugins' `init()` functions are executed +2. all plugins with `lazy=false` are loaded. This includes sourcing `/plugin` and `/ftdetect` files. (`/after` will not be sourced yet) +3. all files from `/plugin` and `/ftdetect` directories in you rtp are sourced (excluding `/after`) +4. all `/after/plugin` files are sourced (this inludes `/after` from plugins) Files from runtime directories are always sourced in alphabetical order. diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua index 2e66930..2da7f97 100644 --- a/lua/lazy/core/loader.lua +++ b/lua/lazy/core/loader.lua @@ -58,36 +58,7 @@ function M.startup() -- backup original rtp local rtp = vim.opt.rtp:get() - -- 1. load start plugin - Util.track({ start = "start" }) - for _, plugin in pairs(Config.plugins) do - if plugin.lazy == false then - M.load(plugin, { start = "start" }) - end - end - Util.track() - - -- 2. load plugins from rtp, excluding after - Util.track({ start = "rtp plugins" }) - for _, path in ipairs(rtp) do - if not path:find("after/?$") then - M.packadd(path) - end - end - Util.track() - - -- 3. load after plugins - Util.track({ start = "after" }) - for _, path in ipairs(vim.opt.rtp:get()) do - if path:find("after/?$") then - M.source_runtime(path, "plugin") - end - end - Util.track() - - M.init_done = true - - -- 4. run plugin init + -- 1. run plugin init Util.track({ start = "init" }) for _, plugin in pairs(Config.plugins) do if plugin.init then @@ -98,6 +69,35 @@ function M.startup() end Util.track() + -- 2. load start plugin + Util.track({ start = "start" }) + for _, plugin in pairs(Config.plugins) do + if plugin.lazy == false and not plugin._.loaded then + M.load(plugin, { start = "start" }) + end + end + Util.track() + + -- 3. load plugins from rtp, excluding after + Util.track({ start = "rtp plugins" }) + for _, path in ipairs(rtp) do + if not path:find("after/?$") then + M.packadd(path) + end + end + Util.track() + + -- 4. load after plugins + Util.track({ start = "after" }) + for _, path in ipairs(vim.opt.rtp:get()) do + if path:find("after/?$") then + M.source_runtime(path, "plugin") + end + end + Util.track() + + M.init_done = true + Util.track() end diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua index fbd676d..844db73 100644 --- a/lua/lazy/core/plugin.lua +++ b/lua/lazy/core/plugin.lua @@ -18,7 +18,7 @@ local M = {} ---@class LazyPluginHooks ---@field init? fun(LazyPlugin) Will always be run ----@field config? fun(LazyPlugin) Will be executed when loading the plugin +---@field config? fun(LazyPlugin)|true|table Will be executed when loading the plugin ---@field build? string|fun(LazyPlugin) ---@class LazyPluginHandlers: table