refactor: move core modules needed for loading under core

This commit is contained in:
Folke Lemaitre 2022-11-22 21:28:08 +01:00
parent 3218c2d9ec
commit fca984b18c
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
12 changed files with 27 additions and 32 deletions

View File

@ -1,4 +1,4 @@
local Util = require("lazy.util") local Util = require("lazy.core.util")
local M = {} local M = {}

View File

@ -1,5 +1,5 @@
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Config = require("lazy.config") local Config = require("lazy.core.config")
local M = {} local M = {}

View File

@ -102,9 +102,9 @@ function M.setup()
-- preload core modules -- preload core modules
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h") local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h")
for _, name in ipairs({ "util", "config", "plugin", "loader", "core.state" }) do for _, name in ipairs({ "util", "config", "loader", "state" }) do
local modname = "lazy." .. name local modname = "lazy.core." .. name
M.add(modname, root .. "/" .. name:gsub("%.", "/") .. ".lua") M.add(modname, root .. "/core/" .. name:gsub("%.", "/") .. ".lua")
end end
table.insert(package.loaders, 2, function(modname) table.insert(package.loaders, 2, function(modname)

View File

@ -7,13 +7,13 @@ M.functions = { "init", "config", "run" }
M.changed = true M.changed = true
function M.save() function M.save()
local Config = require("lazy.config") local Config = require("lazy.core.config")
---@class LazyState ---@class LazyState
local state = { local state = {
---@type LazyPlugin[] ---@type LazyPlugin[]
plugins = {}, plugins = {},
loaders = require("lazy.loader").loaders, loaders = require("lazy.core.loader").loaders,
config = Config.options, config = Config.options,
} }
@ -61,8 +61,8 @@ function M.load()
return false return false
end end
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Config = require("lazy.config") local Config = require("lazy.core.config")
if not vim.deep_equal(Config.options, state.config) then if not vim.deep_equal(Config.options, state.config) then
Cache.dirty() Cache.dirty()
@ -89,9 +89,7 @@ function M.load()
plugin.installed = installed[plugin.opt and "opt" or "start"][plugin.pack] plugin.installed = installed[plugin.opt and "opt" or "start"][plugin.pack]
if plugin.modname then if plugin.modname then
-- mark module as used -- mark module as used
if not Cache.get(plugin.modname) then assert(Cache.get(plugin.modname))
Util.error("Module missing for " .. plugin.name)
end
for _, fun in ipairs(M.functions) do for _, fun in ipairs(M.functions) do
if plugin[fun] == true then if plugin[fun] == true then
plugin[fun] = function(...) plugin[fun] = function(...)
@ -102,10 +100,7 @@ function M.load()
else else
for _, fun in ipairs(M.functions) do for _, fun in ipairs(M.functions) do
if type(plugin[fun]) == "number" then if type(plugin[fun]) == "number" then
local chunk = Cache.get("cache.state.fun." .. plugin[fun]) local chunk = assert(Cache.get("cache.state.fun." .. plugin[fun]))
if not chunk then
Util.error("Chunk missing for " .. plugin.name)
end
plugin[fun] = function(...) plugin[fun] = function(...)
plugin[fun] = loadstring(chunk) plugin[fun] = loadstring(chunk)
return plugin[fun](...) return plugin[fun](...)
@ -116,7 +111,7 @@ function M.load()
end end
-- loaders -- loaders
local Loader = require("lazy.loader") local Loader = require("lazy.core.loader")
Loader.loaders = state.loaders Loader.loaders = state.loaders
M.changed = false M.changed = false

View File

@ -19,9 +19,9 @@ function M.setup(opts)
local Module = require("lazy.core.module").setup() local Module = require("lazy.core.module").setup()
local require_start = vim.loop.hrtime() local require_start = vim.loop.hrtime()
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Config = require("lazy.config") local Config = require("lazy.core.config")
local Loader = require("lazy.loader") local Loader = require("lazy.core.loader")
local State = require("lazy.core.state") local State = require("lazy.core.state")
Util.track("cache.setup", module_start - cache_start) Util.track("cache.setup", module_start - cache_start)
@ -87,7 +87,7 @@ function M.stats()
loaded = 0, loaded = 0,
} }
for _, plugin in pairs(require("lazy.config").plugins) do for _, plugin in pairs(require("lazy.core.config").plugins) do
ret.count = ret.count + 1 ret.count = ret.count + 1
if plugin.loaded then if plugin.loaded then

View File

@ -1,7 +1,7 @@
local Config = require("lazy.config") local Config = require("lazy.core.config")
local Task = require("lazy.task") local Task = require("lazy.task")
local Runner = require("lazy.runner") local Runner = require("lazy.runner")
local Util = require("lazy.util") local Util = require("lazy.core.util")
local M = {} local M = {}

View File

@ -1,5 +1,5 @@
local Config = require("lazy.config") local Config = require("lazy.core.config")
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Module = require("lazy.core.module") local Module = require("lazy.core.module")
local M = {} local M = {}

View File

@ -1,6 +1,6 @@
local Process = require("lazy.process") local Process = require("lazy.process")
local Loader = require("lazy.loader") local Loader = require("lazy.core.loader")
local Util = require("lazy.util") local Util = require("lazy.core.util")
---@class LazyTask ---@class LazyTask
---@field plugin LazyPlugin ---@field plugin LazyPlugin

View File

@ -1,4 +1,4 @@
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Render = require("lazy.view.render") local Render = require("lazy.view.render")
local M = {} local M = {}

View File

@ -1,5 +1,5 @@
local Config = require("lazy.config") local Config = require("lazy.core.config")
local Util = require("lazy.util") local Util = require("lazy.core.util")
local Manager = require("lazy.manager") local Manager = require("lazy.manager")
local Sections = require("lazy.view.sections") local Sections = require("lazy.view.sections")

View File

@ -1,4 +1,4 @@
local Config = require("lazy.config") local Config = require("lazy.core.config")
---@alias TextSegment {str: string, hl?:string, extmark?:table} ---@alias TextSegment {str: string, hl?:string, extmark?:table}