Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for packages [WIP] #1530

Merged
merged 26 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c2eff49
feat: packspec
folke Jun 18, 2024
2d4f2cb
feat: luarocks support
folke Jun 18, 2024
1e0ab05
feat: added support for plugin packages by lazy, rockspec and packspec
folke Jun 18, 2024
59b9d3c
test: fix spec tests
folke Jun 18, 2024
7070cf6
feat: rewrite of spec resolving
folke Jun 22, 2024
a2b05c3
feat(pkg): import package specs in the scope of the plugin
folke Jun 22, 2024
c37e1a4
docs: added doc comments
folke Jun 22, 2024
9ca807f
docs: added comment on package source order
folke Jun 23, 2024
d7bc9ce
feat(meta): check for dir changes for plugins already added to the rtp
folke Jun 23, 2024
93552cd
fix(pkg): correctly pre-load package specs and remove them when neede…
folke Jun 23, 2024
66ea0ac
feat!: new docs for v11.0
folke Jun 23, 2024
5a311d0
fix(pkg): versioning and reload specs when pkg-cache is dirty
folke Jun 23, 2024
70f5407
fix(pkg): make sure state dir exists
folke Jun 23, 2024
7e20395
fix(pkg): automatically update pkgs when editing a pkg file
folke Jun 23, 2024
4413654
docs: fix default lazy-loading comment
folke Jun 24, 2024
7dcc1c2
chore(build): auto-generate docs
github-actions[bot] Jun 24, 2024
cb9c5a9
style: wording
folke Jun 24, 2024
10114ef
chore(build): auto-generate docs
github-actions[bot] Jun 24, 2024
6624905
chore(build): auto-generate docs
github-actions[bot] Jun 24, 2024
73ea05f
feat: spec.rocks is no longer needed & added support for installing a…
folke Jun 24, 2024
97704cf
feat(build): build files and functions are now async. use coroutine.y…
folke Jun 24, 2024
f8dd282
fix(luarocks): cleanup luarocks when deleting a plugin
folke Jun 24, 2024
01249cd
chore(build): auto-generate docs
github-actions[bot] Jun 24, 2024
71dec6e
fix(fragments): prevent adding the same spec instance more than once
folke Jun 24, 2024
624b881
fix(rocks): only build rockspec when it has deps or an advanced build…
folke Jun 24, 2024
7dfefcc
chore(build): auto-generate docs
github-actions[bot] Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,10 @@ jobs:
nvim --version
[ ! -d tests ] && exit 0
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}"
docs:
runs-on: ubuntu-latest
needs: tests
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v4
- name: panvimdoc
uses: kdheepak/panvimdoc@main
with:
vimdoc: lazy.nvim
version: "Neovim >= 0.8.0"
demojify: true
treesitter: true
- name: Push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(build): auto-generate vimdoc"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
release:
name: release
if: ${{ github.ref == 'refs/heads/main' }}
needs:
- docs
- tests
runs-on: ubuntu-latest
steps:
Expand Down
845 changes: 35 additions & 810 deletions README.md

Large diffs are not rendered by default.

Empty file added doc/.keep
Empty file.
1,088 changes: 656 additions & 432 deletions doc/lazy.nvim.txt

Large diffs are not rendered by default.

41 changes: 33 additions & 8 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ local M = {}
M.defaults = {
root = vim.fn.stdpath("data") .. "/lazy", -- directory where plugins will be installed
defaults = {
-- Set this to `true` to have all your plugins lazy-loaded by default.
-- Only do this if you know what you are doing, as it can lead to unexpected behavior.
lazy = false, -- should plugins be lazy-loaded?
version = nil,
-- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
-- have outdated releases, which may break your Neovim install.
version = nil, -- always use the latest git commit
-- version = "*", -- try installing the latest stable version for plugins that support semver
-- default `cond` you can use to globally disable a lot of plugins
-- when running inside vscode for example
cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil
-- version = "*", -- enable this to try installing the latest stable versions of plugins
},
-- leave nil when passing the spec as the first argument to setup()
spec = nil, ---@type LazySpec
Expand All @@ -31,6 +35,21 @@ M.defaults = {
-- increase downloads a lot.
filter = true,
},
pkg = {
enabled = true,
cache = vim.fn.stdpath("state") .. "/lazy/pkg-cache.lua",
versions = true, -- Honor versions in pkg sources
-- the first package source that is found for a plugin will be used.
sources = {
"lazy",
"rockspec",
"packspec",
},
},
rocks = {
root = vim.fn.stdpath("data") .. "/lazy-rocks",
server = "https://nvim-neorocks.github.io/rocks-binaries/",
},
dev = {
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects
path = "~/projects",
Expand Down Expand Up @@ -164,12 +183,6 @@ M.defaults = {
skip_if_doc_exists = true,
},
state = vim.fn.stdpath("state") .. "/lazy/state.json", -- state info for checker and other things
build = {
-- Plugins can provide a `build.lua` file that will be executed when the plugin is installed
-- or updated. When the plugin spec also has a `build` command, the plugin's `build.lua` not be
-- executed. In this case, a warning message will be shown.
warn_on_override = true,
},
-- Enable profiling of lazy.nvim. This will add some overhead,
-- so only enable this when you are debugging lazy.nvim
profiling = {
Expand Down Expand Up @@ -281,6 +294,18 @@ function M.setup(opts)
require("lazy.manage.checker").start()
end, 10)
end

-- useful for plugin developers when making changes to a packspec file
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "lazy.lua", "pkg.json", "*.rockspec" },
callback = function()
require("lazy").pkg({
plugins = {
require("lazy.core.plugin").find(vim.uv.cwd() .. "/lua/"),
},
})
end,
})
end,
})

Expand Down
174 changes: 174 additions & 0 deletions lua/lazy/core/fragments.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
local Config = require("lazy.core.config")
local Util = require("lazy.core.util")

--- This class is used to manage the fragments of a plugin spec.
--- It keeps track of the fragments and their relations to other fragments.
--- A fragment can be a dependency (dependencies) or a child (specs) of another fragment.
---@class LazyFragments
---@field fragments table<number, LazyFragment>
---@field frag_stack number[]
---@field dep_stack number[]
---@field dirty table<number, boolean>
---@field plugins table<LazyPlugin, number>
---@field spec LazySpecLoader
local M = {}

M._fid = 0

local function next_id()
M._fid = M._fid + 1
return M._fid
end

---@param spec LazySpecLoader
---@return LazyFragments
function M.new(spec)
local self = setmetatable({}, { __index = M })
self.fragments = {}
self.frag_stack = {}
self.dep_stack = {}
self.spec = spec
self.dirty = {}
self.plugins = {}
return self
end

---@param id number
function M:get(id)
return self.fragments[id]
end

--- Remove a fragment and all its children.
--- This will also remove the fragment from its parent's children list.
---@param id number
function M:del(id)
-- del fragment
local fragment = self.fragments[id]
if not fragment then
return
end

self.dirty[id] = true

-- remove from parent
local pid = fragment.pid
if pid then
local parent = self.fragments[pid]
if parent.frags then
---@param fid number
parent.frags = Util.filter(function(fid)
return fid ~= id
end, parent.frags)
end
if parent.deps then
---@param fid number
parent.deps = Util.filter(function(fid)
return fid ~= id
end, parent.deps)
end
self.dirty[pid] = true
end

-- remove children
if fragment.frags then
for _, fid in ipairs(fragment.frags) do
self:del(fid)
end
end

self.fragments[id] = nil
end

--- Add a fragment to the fragments list.
--- This also resolves its name, url, dir, dependencies and child specs.
---@param plugin LazyPluginSpec
function M:add(plugin)
if self.plugins[plugin] then
return self.fragments[self.plugins[plugin]]
end

local id = next_id()
setmetatable(plugin, nil)

self.plugins[plugin] = id

local pid = self.frag_stack[#self.frag_stack]

---@type LazyFragment
local fragment = {
id = id,
pid = pid,
name = plugin.name,
url = plugin.url,
dir = plugin.dir,
spec = plugin --[[@as LazyPlugin]],
}

-- short url / ref
if plugin[1] then
local slash = plugin[1]:find("/", 1, true)
if slash then
local prefix = plugin[1]:sub(1, 4)
if prefix == "http" or prefix == "git@" then
fragment.url = fragment.url or plugin[1]
else
fragment.name = fragment.name or plugin[1]:sub(slash + 1)
fragment.url = fragment.url or Config.options.git.url_format:format(plugin[1])
end
else
fragment.name = fragment.name or plugin[1]
end
end

-- name
fragment.name = fragment.name
or fragment.url and self.spec.get_name(fragment.url)
or fragment.dir and self.spec.get_name(fragment.dir)
if not fragment.name then
return self.spec:error("Invalid plugin spec " .. vim.inspect(plugin))
end

if type(plugin.config) == "table" then
self.spec:warn(
"{" .. fragment.name .. "}: setting a table to `Plugin.config` is deprecated. Please use `Plugin.opts` instead"
)
---@diagnostic disable-next-line: assign-type-mismatch
plugin.opts = plugin.config
plugin.config = nil
end

self.fragments[id] = fragment

-- add to parent
if pid then
local parent = self.fragments[pid]
parent.frags = parent.frags or {}
table.insert(parent.frags, id)
end

-- add to parent's deps
local did = self.dep_stack[#self.dep_stack]
if did and did == pid then
fragment.dep = true
local parent = self.fragments[did]
parent.deps = parent.deps or {}
table.insert(parent.deps, id)
end

table.insert(self.frag_stack, id)
-- dependencies
if plugin.dependencies then
table.insert(self.dep_stack, id)
self.spec:normalize(plugin.dependencies)
table.remove(self.dep_stack)
end
-- child specs
if plugin.specs then
self.spec:normalize(plugin.specs)
end
table.remove(self.frag_stack)

return fragment
end

return M
27 changes: 23 additions & 4 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function M.setup()
while M.install_missing() do
count = count + 1
if count > 5 then
Util.error("Too many rounds of missing plugins")
break
end
end
Expand All @@ -66,7 +67,10 @@ end
-- multiple rounds can happen when importing a spec from a missing plugin
function M.install_missing()
for _, plugin in pairs(Config.plugins) do
if not (plugin._.installed or Plugin.has_errors(plugin)) then
local installed = plugin._.installed
local has_errors = Plugin.has_errors(plugin)

if not has_errors and not (installed and not plugin._.build) then
for _, colorscheme in ipairs(Config.options.install.colorscheme) do
if colorscheme == "default" then
break
Expand Down Expand Up @@ -100,7 +104,7 @@ function M.startup()
M.source(vim.env.VIMRUNTIME .. "/filetype.lua")

-- backup original rtp
local rtp = vim.opt.rtp:get()
local rtp = vim.opt.rtp:get() --[[@as string[] ]]

-- 1. run plugin init
Util.track({ start = "init" })
Expand Down Expand Up @@ -131,15 +135,17 @@ function M.startup()
if not path:find("after/?$") then
-- these paths don't will already have their ftdetect ran,
-- by sourcing filetype.lua above, so skip them
M.did_ftdetect[path] = true
M.did_ftdetect[path] = path
M.packadd(path)
end
end
Util.track()

-- 4. load after plugins
Util.track({ start = "after" })
for _, path in ipairs(vim.opt.rtp:get()) do
for _, path in
ipairs(vim.opt.rtp:get() --[[@as string[] ]])
do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
end
Expand Down Expand Up @@ -337,6 +343,10 @@ function M._load(plugin, reason, opts)

M.add_to_rtp(plugin)

if plugin._.pkg and plugin._.pkg.source == "rockspec" then
M.add_to_luapath(plugin)
end

if plugin.dependencies then
Util.try(function()
M.load(plugin.dependencies, {})
Expand Down Expand Up @@ -480,6 +490,15 @@ function M.add_to_rtp(plugin)
vim.opt.rtp = rtp
end

---@param plugin LazyPlugin
function M.add_to_luapath(plugin)
local root = Config.options.rocks.root .. "/" .. plugin.name
local path = root .. "/share/lua/5.1"
local cpath = root .. "/lib/lua/5.1"
package.path = package.path .. ";" .. path .. "/?.lua;" .. path .. "/?/init.lua;"
package.cpath = package.cpath .. ";" .. cpath .. "/?." .. (jit.os:find("Windows") and "dll" or "so") .. ";"
end

function M.source(path)
Util.track({ runtime = path })
Util.try(function()
Expand Down
Loading