folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.78k stars 359 forks source link

bug: plugin is not configured during build on first install #1806

Closed stefanboca closed 5 hours ago

stefanboca commented 5 hours ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.11.0-dev+1107-g000129201 Build type: RelWithDebInfo LuaJIT 2.1.1720049189

Operating system/version

Fedora 41

Describe the bug

If a plugin has a build function that requires itself, when it is first installed it is not configured until after the build function has finished running - not when it is required.

Steps To Reproduce

On first nvim -u repro.lua, the plugin is installed and the following is printed:

build start
build end
config

Reopening nvim -u repro.lua and running ":Lazy build drop.nvim", the following is printed

build start
config
build end

Expected Behavior

Plugin is configured when required during build, even during first install.

Repro

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    -- do not remove the colorscheme!
    "folke/tokyonight.nvim",
    -- add any other pugins here

    -- this could be any plugin, using drop.nvim as an example
    {
        "folke/drop.nvim",
        lazy = true,
        opts = {},
        build = function()
            vim.print("build start")
            require("drop") -- plugin should be configured here
            vim.print("build end")
        end,
        config = function(_, opts)
            vim.print("config")
            require("drop").setup(opts)
        end,
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme!
vim.cmd([[colorscheme tokyonight]])
folke commented 5 hours ago

That is actually on purpose, since typically a plugin that needs a build step, needs that step completed before it can be setup.