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

bug: dependencies of disabled plugins break optional calculation #1402

Closed
3 tasks done
mehalter opened this issue Apr 1, 2024 · 10 comments · Fixed by #1522 or #1526
Closed
3 tasks done

bug: dependencies of disabled plugins break optional calculation #1402

mehalter opened this issue Apr 1, 2024 · 10 comments · Fixed by #1522 or #1526
Labels
bug Something isn't working

Comments

@mehalter
Copy link

mehalter commented Apr 1, 2024

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.5

Operating system/version

Arch Linux

Describe the bug

Given a plugin with some list of dependencies, if the plugin is disabled all of the dependencies should also be disabled if they aren't specified anywhere else.

Similarly if I have a plugin with the optional = true key set it should also be ignored unless the plugin is specified explicitly somewhere.

If I have a plugin defined as optional and also defined as a dependency to a plugin that is disabled the plugin should not be enabled.

My guess is the calculation of optional is happening before filtering out plugin specs for disabled plugins which breaks the behavior of optional.

Steps To Reproduce

  1. nvim -u repro.lua, run the minimal config below
  2. :Lazy, open lazy and see that nvim-cmp is not disabled

Expected Behavior

Plugins listed as dependencies of disabled plugins shouldn't trigger optional plugin specs to be enabled. Since at the time of calculation it is not valid.

Repro

-- DO NOT change the paths and don't remove the colorscheme
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", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "hrsh7th/nvim-cmp", optional = true },
  {
    "mfussenegger/nvim-dap",
    enabled = false,
    dependencies = {
      "hrsh7th/nvim-cmp",
    },
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@mehalter mehalter added the bug Something isn't working label Apr 1, 2024
@mehalter mehalter changed the title bug: optional breaks ignored dependencies bug: dependencies of disabled plugins break optional calculation Apr 1, 2024
@mehalter
Copy link
Author

mehalter commented Apr 1, 2024

Also I noticed the optional specs override the implied "laziness" of a plugin that is only a dependency. Is this intended? It might make more sense for optional plugin specs not influence implied laziness such as that implied by a plugin only being defined as a dependency to another plugin.

@bluebrown
Copy link

I cant get optional decency working at all. I get errors that the plugin is not found.

When I use this config:

require("lazy").setup({
  {
    "projekt0n/github-nvim-theme",
    priority = 1000,
    config = function()
      require("github-theme").setup({ options = { transparent = true } })
      vim.cmd.colorscheme("github_dark_dimmed")
    end,
    dependencies = {
      { "echasnovski/mini.nvim", optional = true, lazy= true }, -- should not load
    },
  },
})

I get this error when i open vim:

Error detected while processing /home/blue/.config/nvim/init.lua:
Plugin mini.nvim not found

@mehalter
Copy link
Author

@bluebrown I am also getting this behavior. It seems like the feature added in #947 has been broken along the way

@abeldekat any idea what has happened?

@abeldekat
Copy link
Contributor

@mehalter, I have no idea. My last contribution was in october 2023.

@konosubakonoakua
Copy link

me too.

@Kruziikrel13
Copy link

Also getting this

@mehalter
Copy link
Author

@folke this issue is still reproducible given the original post instructions. It doesn't seem to be solved at all. Sorry!

@mehalter
Copy link
Author

-- DO NOT change the paths and don't remove the colorscheme
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", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	{
		"mfussenegger/nvim-dap",
		dependencies = {
			{ "hrsh7th/nvim-cmp", optional = true },
		},
	},
	-- add any other plugins here
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

this repro.lua is also a bug. This is saying nvim-cmp is an optional dependency but if it is available it needs to be loaded before nvim-dap and it just throws an error.

So neither of the bugs reported here were resolved in the latest version

@folke folke reopened this Jun 16, 2024
@folke folke closed this as completed in b4316da Jun 16, 2024
@folke
Copy link
Owner

folke commented Jun 16, 2024

You're right. Both should be fixed now. Let me know if you still see any issues!

@mehalter
Copy link
Author

This looks like it works beautifully with the 2 test cases mentioned here! Thanks so much for the fix! I'll let you know if I run into any issues down the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants