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: named dependencies not working with opts #833

Closed
3 tasks done
filipekiss opened this issue May 26, 2023 · 4 comments · Fixed by #835
Closed
3 tasks done

bug: named dependencies not working with opts #833

filipekiss opened this issue May 26, 2023 · 4 comments · Fixed by #835
Labels
bug Something isn't working

Comments

@filipekiss
Copy link

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.0 (homebrew)

Operating system/version

macOS 13.3.1

Describe the bug

So, in the plugin spec, dependencies is described as follows:

A list of plugin names or plugin specs that should be loaded when the plugin loads. Dependencies are always lazy-loaded unless specified otherwise. When specifying a name, make sure the plugin spec has been defined somewhere else.

I have a setup where I have one plugin per file and I just { import = { "plugins" } } in my init.lua. There's a minimal example here.

When trying to setup noice and which-key together, noice would complain that which-key.nvim spec if not defined.

return {
	"https://github.com/folke/noice.nvim",
	event = "VeryLazy",
	dependencies = {
		-- which key integration
		{
			"which-key.nvim",
			opts = function(_, opts)
				opts = opts or { defaults = {} }
				opts.defaults["<leader>sn"] = { name = "+noice" }
			end,
		},
		{
			"http://github.com/MunifTanjim/nui.nvim",
			lazy = true,
		},
	},
	opts = {
		presets = {
			bottom_search = true,
			command_palette = true,
			long_message_to_split = true,
			inc_rename = true,
		},
	},
}

But a file does exists that defines which-key.nvim:

return {
	"https://github.com/folke/which-key.nvim",
	event = "VeryLazy",
	opts = {
		plugins = { spelling = true },
		defaults = {
			mode = { "n", "v" },
		},
	},
	config = function(_, opts)
		local wk = require("which-key")
		wk.setup(opts)
		wk.register(opts.defaults)
	end
}

I expected that putting which-key as a dependency for noice, lazy would handle the order, but apparently things are running in alphabetical order for the configuration (1), despite the plugins being loaded correctly for the startup (2).

The result of :Lazy profile

CleanShot 2023-05-27 at 01 31 24@2x

Steps To Reproduce

  1. Load plugin a.lua that depends on plugin b.lua.
  2. Make sure that when declaring the dependency for b.lua, you pass opts. It can be a function or a table. If the opts property is empty this error does not occur
  3. Import the plugins in your init.lua

Expected Behavior

I expected lazy to manage the order of setting the option when referencing named plugins with options.

Repro

Please, see the [example repository](https://github.com/filipekiss/nvim-lazy-debug/)
@filipekiss filipekiss added the bug Something isn't working label May 26, 2023
@filipekiss filipekiss changed the title bug: named dependencies not working bug: named dependencies not working with opts May 27, 2023
@folke folke closed this as completed in 199e100 May 27, 2023
@folke
Copy link
Owner

folke commented May 27, 2023

Should be fixed now. You could have also just used the full url.

You do still have some errors in those specs though.

@filipekiss
Copy link
Author

Thanks for the quick fix! It seems to have resolve the issue.

These specs are reduced versions, just to trigger the error. Curious to know what's wrong with them (maybe I need to fix my actual specs as well).

@folke
Copy link
Owner

folke commented May 28, 2023

The part below:

opts = opts or { defaults = {} }
				opts.defaults["<leader>sn"] = { name = "+noice" }

Unless you're using LazyVim?

@filipekiss
Copy link
Author

Ah, yes. I actually did get that from LazyVim (although I'm no longer using it) so that's why the mapping is the same. I did have to change it a bit as I need to return the opts for my own setup. Thanks for the help!

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.

2 participants