mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
refactor: moved all plugin state to Plugin._
This commit is contained in:
parent
352dbadcb6
commit
28af1e1ac3
9 changed files with 49 additions and 46 deletions
|
@ -46,14 +46,14 @@ function M.load(plugins, reason, opts)
|
|||
plugin = type(plugin) == "string" and Config.plugins[plugin] or plugin
|
||||
---@cast plugin LazyPlugin
|
||||
|
||||
if not plugin.loaded then
|
||||
if not plugin._.loaded then
|
||||
---@diagnostic disable-next-line: assign-type-mismatch
|
||||
plugin.loaded = {}
|
||||
plugin._.loaded = {}
|
||||
for k, v in pairs(reason) do
|
||||
plugin.loaded[k] = v
|
||||
plugin._.loaded[k] = v
|
||||
end
|
||||
if #M.loading > 0 then
|
||||
plugin.loaded.plugin = M.loading[#M.loading].name
|
||||
plugin._.loaded.plugin = M.loading[#M.loading].name
|
||||
end
|
||||
|
||||
table.insert(M.loading, plugin)
|
||||
|
@ -69,7 +69,7 @@ function M.load(plugins, reason, opts)
|
|||
Util.try(plugin.config, "Failed to run `config` for " .. plugin.name)
|
||||
end
|
||||
|
||||
plugin.loaded.time = Util.track().time
|
||||
plugin._.loaded.time = Util.track().time
|
||||
table.remove(M.loading)
|
||||
vim.schedule(function()
|
||||
vim.cmd("do User LazyRender")
|
||||
|
|
|
@ -6,7 +6,7 @@ local Cache = require("lazy.core.cache")
|
|||
local M = {}
|
||||
|
||||
---@alias CachedPlugin LazyPlugin | {_funs: string[]}
|
||||
local skip = { installed = true, loaded = true, tasks = true, dirty = true, dir = true }
|
||||
local skip = { _ = true, dir = true }
|
||||
local funs = { config = true, init = true, run = true }
|
||||
|
||||
M.dirty = false
|
||||
|
@ -29,7 +29,7 @@ M.dirty = false
|
|||
---@field commit? string
|
||||
---@field version? string
|
||||
|
||||
---@class LazyPlugin: LazyPluginHandlers,LazyPluginHooks,LazyPluginState,LazyPluginRef
|
||||
---@class LazyPlugin: LazyPluginHandlers,LazyPluginHooks,LazyPluginRef
|
||||
---@field [1] string
|
||||
---@field name string display name and name used for plugin config files
|
||||
---@field uri string
|
||||
|
@ -37,6 +37,7 @@ M.dirty = false
|
|||
---@field enabled? boolean|(fun():boolean)
|
||||
---@field opt? boolean
|
||||
---@field requires? string[]
|
||||
---@field _ LazyPluginState
|
||||
|
||||
---@alias LazySpec string|LazyPlugin|LazySpec[]|{requires:LazySpec}
|
||||
|
||||
|
@ -69,6 +70,7 @@ function Spec:add(plugin)
|
|||
Util.error("Invalid plugin spec " .. vim.inspect(plugin))
|
||||
end
|
||||
plugin.uri = plugin.uri or ("https://github.com/" .. plugin[1] .. ".git")
|
||||
plugin._ = {}
|
||||
|
||||
-- PERF: optimized code to get package name without using lua patterns
|
||||
if not plugin.name then
|
||||
|
@ -133,11 +135,12 @@ function M.update_state(check_clean)
|
|||
end
|
||||
|
||||
for _, plugin in pairs(Config.plugins) do
|
||||
plugin._ = plugin._ or {}
|
||||
plugin[1] = plugin["1"] or plugin[1]
|
||||
plugin.opt = plugin.opt == nil and Config.options.opt or plugin.opt
|
||||
local opt = plugin.opt and "opt" or "start"
|
||||
plugin.dir = Config.options.package_path .. "/" .. opt .. "/" .. plugin.name
|
||||
plugin.installed = installed[opt][plugin.name] == true
|
||||
plugin._.installed = installed[opt][plugin.name] == true
|
||||
installed[opt][plugin.name] = nil
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue