lazy.nvim icon indicating copy to clipboard operation
lazy.nvim copied to clipboard

feature: Allow plugins to configure their own laziness

Open tomodachi94 opened this issue 2 years ago • 7 comments

Did you check the docs?

  • [X] I have read all the lazy.nvim docs

Is your feature request related to a problem? Please describe.

Sometimes, setting up Lazy to use lazy-loading can be a little repetitive. The user needs to find a list of commands for the plugin, and then they need to specify them all. This isn't very resilient to plugin updates where commands are added or removed.

Describe the solution you'd like

Plugin developers should be able to specify a file in lua/lazy/_automatic/<pluginName>.lua[^1]which gets required[^2] by Lazy itself. The automatic setup file should return a table with all of the Lazy triggers: cond, event, cmd, and ft. It should not be able to set anything else, including priority.

This automatic setup should only be triggered if lazy is set to true. User-specified values should overwrite pre-determined values.

Describe alternatives you've considered

See "Is your feature request related to a problem".

Additional context

The trouble with this is finding a way to use "path safe" plugin names, as require interprets a dot . as a slash /.

[^1]: I modeled the name after Telescope's _extensions submodule. It can be whatever. [^2]: Something like require("lazy._automatic" .. pluginName) would work, plus it looks clean.

tomodachi94 avatar Jan 07 '23 02:01 tomodachi94

Perhaps there should be a new option, automatic, which could be set to false to completely disable this functionality.

Alternatively, it could require setting automatic and lazy to true, which would be less shocking for the end-user.

tomodachi94 avatar Jan 07 '23 02:01 tomodachi94

Another thing I forgot to mention is if we should let this functionality manage dependencies (I think we shouldn't, it's too easy to screw up and doesn't account for non-plugin dependencies).

tomodachi94 avatar Jan 07 '23 05:01 tomodachi94

That's already planned.

folke avatar Jan 07 '23 07:01 folke

That's already planned.

Ah, my bad.

tomodachi94 avatar Jan 07 '23 07:01 tomodachi94

@folke, if you need help implementing this, I'm more than willing to help.

tomodachi94 avatar Jan 07 '23 22:01 tomodachi94

I first need to think this through to keep everything performant. I'm probably going to disallow the usage of functions inside plugins' specs, so that all that data can be cached and only needs to be updated when a plugin updates.

I would actually allow using these files even when the default for lazy is false, since if something's not working due to lazy-loading, it's the plugin dev that needs to fix it anyway.

I'll keep this issue open for now.

folke avatar Jan 07 '23 22:01 folke

I'm also looking to support https://github.com/nvim-lua/nvim-package-specification directly.

folke avatar Jan 07 '23 22:01 folke