nvim-neorocks / rocks.nvim

🌒 Neovim plugin management inspired by Cargo, powered by luarocks
GNU General Public License v3.0
729 stars 15 forks source link

[Feature] Add an API to support lazy loading plugins #86

Closed mrcjkb closed 11 months ago

mrcjkb commented 11 months ago

This would mean two things:

[plugins]
neorg = { opt = true, version = "1.0.0" }
NTBBloodbath commented 11 months ago

To keep the lazy loading to just what is necessary, I think adding an opts table to the API function that accepts two possible arguments (ft and event) for faster integration could be nice. For example, to have nvim-lspconfig loaded only on certain filetypes in which you have its LSP installed in your system. Here is an example

--- Load lspconfig only in the following filetypes
--- as I have installed their LSPs for daily use
rocks.api.load_plugin("lspconfig", {
    ft = { "lua", "python", "haskell" },
})

Ps: will the function work based on the name of the plugin or the name of its Lua module (e.g. nvim-lspconfig or lspconfig)?


Edit: I don't think that both table options should coexist if implemented, I don't know if it could cause bugs in some plugins or create race conditions in some others.

Edit 2: I just saw the proposal for the rocks-lazy module and its possible configuration. Would the proposal mentioned here serve to make things easier or will an internal wrapper be created in that module?

mrcjkb commented 11 months ago

will the function work based on the name of the plugin or the name of its Lua module

plugin name.

I just saw the proposal for the rocks-lazy module and its possible configuration. Would the proposal mentioned here serve to make things easier or will an internal wrapper be created in that module?

I think the rocks.nvim API should be as simple as possible. That is, no lazy loading logic whatsoever. We just provide the API for loading the plugins manually, and the opt config option that allows users to prevent rocks.nvim from eagerly loading the plugins.

Any lazy loading logic and additional options should be the responsibility of the external module. For example rocks-git.nvim adds a bunch of fields (git, rev, build, ...) to the rocks.toml schema. rocks.nvim itself knows nothing about these fields. It simply sends the config to the injected handler, which detects if it has a git field and does something with it.