mirror of https://github.com/folke/lazy.nvim.git
feat: added support for local spec files `.lazy.lua`
This commit is contained in:
parent
ea7b9c3c3f
commit
9dde1f1bce
69
README.md
69
README.md
|
@ -307,6 +307,7 @@ return {
|
||||||
},
|
},
|
||||||
-- leave nil when passing the spec as the first argument to setup()
|
-- leave nil when passing the spec as the first argument to setup()
|
||||||
spec = nil, ---@type LazySpec
|
spec = nil, ---@type LazySpec
|
||||||
|
local_spec = true, -- load project specific .lazy.lua spec files. They will be added at the end of the spec.
|
||||||
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
||||||
---@type number? limit the maximum amount of concurrent tasks
|
---@type number? limit the maximum amount of concurrent tasks
|
||||||
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
|
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
|
||||||
|
@ -517,7 +518,7 @@ Any operation can be started from the UI, with a sub command or an API function:
|
||||||
<!-- commands:start -->
|
<!-- commands:start -->
|
||||||
|
|
||||||
| Command | Lua | Description |
|
| Command | Lua | Description |
|
||||||
| --- | --- | --- |
|
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
|
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
|
||||||
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
|
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
|
||||||
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
|
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
|
||||||
|
@ -785,39 +786,39 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori
|
||||||
<!-- colors:start -->
|
<!-- colors:start -->
|
||||||
|
|
||||||
| Highlight Group | Default Group | Description |
|
| Highlight Group | Default Group | Description |
|
||||||
| --- | --- | --- |
|
| --------------------- | -------------------------- | --------------------------------------------------- |
|
||||||
| **LazyButton** | ***CursorLine*** | |
|
| **LazyButton** | **_CursorLine_** | |
|
||||||
| **LazyButtonActive** | ***Visual*** | |
|
| **LazyButtonActive** | **_Visual_** | |
|
||||||
| **LazyComment** | ***Comment*** | |
|
| **LazyComment** | **_Comment_** | |
|
||||||
| **LazyCommit** | ***@variable.builtin*** | commit ref |
|
| **LazyCommit** | **_@variable.builtin_** | commit ref |
|
||||||
| **LazyCommitIssue** | ***Number*** | |
|
| **LazyCommitIssue** | **_Number_** | |
|
||||||
| **LazyCommitScope** | ***Italic*** | conventional commit scope |
|
| **LazyCommitScope** | **_Italic_** | conventional commit scope |
|
||||||
| **LazyCommitType** | ***Title*** | conventional commit type |
|
| **LazyCommitType** | **_Title_** | conventional commit type |
|
||||||
| **LazyDimmed** | ***Conceal*** | property |
|
| **LazyDimmed** | **_Conceal_** | property |
|
||||||
| **LazyDir** | ***@markup.link*** | directory |
|
| **LazyDir** | **_@markup.link_** | directory |
|
||||||
| **LazyH1** | ***IncSearch*** | home button |
|
| **LazyH1** | **_IncSearch_** | home button |
|
||||||
| **LazyH2** | ***Bold*** | titles |
|
| **LazyH2** | **_Bold_** | titles |
|
||||||
| **LazyLocal** | ***Constant*** | |
|
| **LazyLocal** | **_Constant_** | |
|
||||||
| **LazyNoCond** | ***DiagnosticWarn*** | unloaded icon for a plugin where `cond()` was false |
|
| **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false |
|
||||||
| **LazyNormal** | ***NormalFloat*** | |
|
| **LazyNormal** | **_NormalFloat_** | |
|
||||||
| **LazyProgressDone** | ***Constant*** | progress bar done |
|
| **LazyProgressDone** | **_Constant_** | progress bar done |
|
||||||
| **LazyProgressTodo** | ***LineNr*** | progress bar todo |
|
| **LazyProgressTodo** | **_LineNr_** | progress bar todo |
|
||||||
| **LazyProp** | ***Conceal*** | property |
|
| **LazyProp** | **_Conceal_** | property |
|
||||||
| **LazyReasonCmd** | ***Operator*** | |
|
| **LazyReasonCmd** | **_Operator_** | |
|
||||||
| **LazyReasonEvent** | ***Constant*** | |
|
| **LazyReasonEvent** | **_Constant_** | |
|
||||||
| **LazyReasonFt** | ***Character*** | |
|
| **LazyReasonFt** | **_Character_** | |
|
||||||
| **LazyReasonImport** | ***Identifier*** | |
|
| **LazyReasonImport** | **_Identifier_** | |
|
||||||
| **LazyReasonKeys** | ***Statement*** | |
|
| **LazyReasonKeys** | **_Statement_** | |
|
||||||
| **LazyReasonPlugin** | ***Special*** | |
|
| **LazyReasonPlugin** | **_Special_** | |
|
||||||
| **LazyReasonRequire** | ***@variable.parameter*** | |
|
| **LazyReasonRequire** | **_@variable.parameter_** | |
|
||||||
| **LazyReasonRuntime** | ***@macro*** | |
|
| **LazyReasonRuntime** | **_@macro_** | |
|
||||||
| **LazyReasonSource** | ***Character*** | |
|
| **LazyReasonSource** | **_Character_** | |
|
||||||
| **LazyReasonStart** | ***@variable.member*** | |
|
| **LazyReasonStart** | **_@variable.member_** | |
|
||||||
| **LazySpecial** | ***@punctuation.special*** | |
|
| **LazySpecial** | **_@punctuation.special_** | |
|
||||||
| **LazyTaskError** | ***ErrorMsg*** | task errors |
|
| **LazyTaskError** | **_ErrorMsg_** | task errors |
|
||||||
| **LazyTaskOutput** | ***MsgArea*** | task output |
|
| **LazyTaskOutput** | **_MsgArea_** | task output |
|
||||||
| **LazyUrl** | ***@markup.link*** | url |
|
| **LazyUrl** | **_@markup.link_** | url |
|
||||||
| **LazyValue** | ***@string*** | value of a property |
|
| **LazyValue** | **_@string_** | value of a property |
|
||||||
|
|
||||||
<!-- colors:end -->
|
<!-- colors:end -->
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ M.defaults = {
|
||||||
},
|
},
|
||||||
-- leave nil when passing the spec as the first argument to setup()
|
-- leave nil when passing the spec as the first argument to setup()
|
||||||
spec = nil, ---@type LazySpec
|
spec = nil, ---@type LazySpec
|
||||||
|
local_spec = true, -- load project specific .lazy.lua spec files. They will be added at the end of the spec.
|
||||||
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
|
||||||
---@type number? limit the maximum amount of concurrent tasks
|
---@type number? limit the maximum amount of concurrent tasks
|
||||||
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
|
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
local Handler = require("lazy.core.handler")
|
|
||||||
local Util = require("lazy.core.util")
|
local Util = require("lazy.core.util")
|
||||||
|
|
||||||
---@class LazyCorePlugin
|
---@class LazyCorePlugin
|
||||||
|
@ -20,6 +19,7 @@ local Spec = {}
|
||||||
M.Spec = Spec
|
M.Spec = Spec
|
||||||
M.last_fid = 0
|
M.last_fid = 0
|
||||||
M.fid_stack = {} ---@type number[]
|
M.fid_stack = {} ---@type number[]
|
||||||
|
M.LOCAL_SPEC = ".lazy.lua"
|
||||||
|
|
||||||
---@param spec? LazySpec
|
---@param spec? LazySpec
|
||||||
---@param opts? {optional?:boolean}
|
---@param opts? {optional?:boolean}
|
||||||
|
@ -399,10 +399,15 @@ function Spec:import(spec)
|
||||||
|
|
||||||
---@type string[]
|
---@type string[]
|
||||||
local modnames = {}
|
local modnames = {}
|
||||||
|
|
||||||
|
if spec.import == M.LOCAL_SPEC then
|
||||||
|
modnames = { spec.import }
|
||||||
|
else
|
||||||
Util.lsmod(spec.import, function(modname)
|
Util.lsmod(spec.import, function(modname)
|
||||||
modnames[#modnames + 1] = modname
|
modnames[#modnames + 1] = modname
|
||||||
end)
|
end)
|
||||||
table.sort(modnames)
|
table.sort(modnames)
|
||||||
|
end
|
||||||
|
|
||||||
for _, modname in ipairs(modnames) do
|
for _, modname in ipairs(modnames) do
|
||||||
imported = imported + 1
|
imported = imported + 1
|
||||||
|
@ -412,7 +417,12 @@ function Spec:import(spec)
|
||||||
---@diagnostic disable-next-line: no-unknown
|
---@diagnostic disable-next-line: no-unknown
|
||||||
package.loaded[modname] = nil
|
package.loaded[modname] = nil
|
||||||
Util.try(function()
|
Util.try(function()
|
||||||
local mod = require(modname)
|
local mod = nil
|
||||||
|
if modname == M.LOCAL_SPEC then
|
||||||
|
mod = M.local_spec()
|
||||||
|
else
|
||||||
|
mod = require(modname)
|
||||||
|
end
|
||||||
if type(mod) ~= "table" then
|
if type(mod) ~= "table" then
|
||||||
self.importing = nil
|
self.importing = nil
|
||||||
return self:error(
|
return self:error(
|
||||||
|
@ -533,12 +543,30 @@ function M.update_state()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.local_spec()
|
||||||
|
local filepath = vim.fn.fnamemodify(".lazy.lua", ":p")
|
||||||
|
local file = vim.secure.read(filepath)
|
||||||
|
if file then
|
||||||
|
return loadstring(file)()
|
||||||
|
end
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
function M.load()
|
function M.load()
|
||||||
M.loading = true
|
M.loading = true
|
||||||
-- load specs
|
-- load specs
|
||||||
Util.track("spec")
|
Util.track("spec")
|
||||||
Config.spec = Spec.new()
|
Config.spec = Spec.new()
|
||||||
Config.spec:parse({ vim.deepcopy(Config.options.spec), { "folke/lazy.nvim" } })
|
Config.spec:parse({
|
||||||
|
vim.deepcopy(Config.options.spec),
|
||||||
|
{
|
||||||
|
import = ".lazy.lua",
|
||||||
|
cond = function()
|
||||||
|
return Config.options.local_spec and vim.fn.filereadable(M.LOCAL_SPEC) == 1
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{ "folke/lazy.nvim" },
|
||||||
|
})
|
||||||
|
|
||||||
-- override some lazy props
|
-- override some lazy props
|
||||||
local lazy = Config.spec.plugins["lazy.nvim"]
|
local lazy = Config.spec.plugins["lazy.nvim"]
|
||||||
|
|
Loading…
Reference in New Issue