With the lazy.nvim plugin manager, lazy's init() function is triggering the lazy's config() function, not sure why

117 Views Asked by At

I'm going through the README file for lazy.nvim to get more familiar with it. Over the course of experimenting, I ran into something odd and I can't figure out what is going on.

I am loading the "blah" plugin "/root/projects/blah". This directory contains two submodules, "lua/bar/init.lua" and "lua/foo/init.lua".

The contents of "bar/init.lua" are vim.cmd("set number") The contents of "foo/init.lua" are vim.cmd("set background=light")

I have this for my "nvim/init.lua" file:


local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
        {
                -- point to a local dir
                dir = "/root/projects/blah",
                lazy = true,

                -- this will run when plugin is loaded
                config = function()
                        require('foo')
                end,

                -- this will run every time at startup
                init = function()
                        --require('bar')
                end,
        },
}, { })

Note that I have require('bar') commented out. With it commented out, the background remains dark and there are no line numbers. This is expected. However, if I uncomment out require('bar'), I have line numbers from "bar/init.lua" and I have a light background from "foo/init.lua".

I can't figure out why "foo.init.lua" does not run with require('bar') commented out and why it gets run with it commented back in.

**UPDATE: ** If I change require('bar') to something like vim.g.blah = 10, the config function does not get called and so "foo/init.lua" does not get run and the background remains black, as originally expected.

0

There are 0 best solutions below