mkNeovimPlugin: add lazyLoad with lz-n support#2602
mkNeovimPlugin: add lazyLoad with lz-n support#2602mergify[bot] merged 11 commits intonix-community:mainfrom
Conversation
d73d2b6 to
6635837
Compare
lib/options.nix
Outdated
| # Spec loading: | ||
| enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) '' | ||
| When false, or if the function returns false, then ${originalName} will not be included in the spec. | ||
|
|
||
| Equivalence: lz.n => enabled; lazy.nvim => enabled | ||
| ''; | ||
|
|
||
| priority = mkNullable types.number (lazyLoadDefaults.priority or null) '' | ||
| Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. | ||
|
|
||
| Equivalence: lz.n => priority; lazy.nvim => priority | ||
| ''; | ||
|
|
||
| # Spec setup | ||
| # Actions | ||
| beforeAll = mkLuaFn (lazyLoadDefaults.beforeAll or null) '' | ||
| Always executed before any plugins are loaded. | ||
|
|
||
| Equivalence: lz.n => beforeAll; lazy.nvim => init | ||
| ''; | ||
|
|
||
| before = mkLuaFn (lazyLoadDefaults.before or null) '' | ||
| Executed before ${originalName} is loaded. | ||
|
|
||
| Equivalence: lz.n => before; lazy.nvim => None | ||
| ''; | ||
|
|
||
| after = mkLuaFn (lazyLoadDefaults.after or null) '' | ||
| Executed after ${originalName} is loaded. | ||
|
|
||
| Equivalence: lz.n => after; lazy.nvim => config | ||
| ''; | ||
|
|
||
| # Triggers | ||
| event = mkNullable triggerType (lazyLoadDefaults.event or null) '' | ||
| Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` | ||
|
|
||
| Equivalence: lz.n => event; lazy.nvim => event | ||
| ''; | ||
|
|
||
| cmd = mkNullable triggerType (lazyLoadDefaults.cmd or null) '' | ||
| Lazy-load on command. | ||
|
|
||
| Equivalence: lz.n => cmd; lazy.nvim => cmd | ||
| ''; | ||
|
|
||
| ft = mkNullable triggerType (lazyLoadDefaults.ft or null) '' | ||
| Lazy-load on filetype. | ||
|
|
||
| Equivalence: lz.n => ft; lazy.nvim => ft | ||
| ''; | ||
|
|
||
| keys = mkListOf (types.attrsOf types.anything) (lazyLoadDefaults.keys or null) '' | ||
| Lazy-load on key mapping. | ||
|
|
||
| Equivalence: lz.n => keys; lazy.nvim => keys | ||
| ''; | ||
|
|
||
| colorscheme = mkNullable triggerType (lazyLoadDefaults.colorscheme or null) '' | ||
| Lazy-load on colorscheme. | ||
|
|
||
| Equivalence: lz.n => colorscheme; lazy.nvim => None | ||
| ''; | ||
|
|
||
| extraSettings = mkSettingsOption { | ||
| description = '' | ||
| Extra settings to pass to the lazy loader backend. | ||
| ''; | ||
| example = { | ||
| dependencies = { | ||
| __unkeyed-1 = "nvim-lua/plenary.nvim"; | ||
| lazy = true; | ||
| }; | ||
| }; |
There was a problem hiding this comment.
It would maybe be better to only support a backendSettings option of type attrsOf anything, that will be passed to the code that implements the lazy loading provider.
I'm not confident that we can find a common API for all possible lazy loading schemes
There was a problem hiding this comment.
That makes sense. I was just changing the options nesting path and this would fit nicely. We can wrap all the backendSettings in a mkSettingsOption style option with the known options specified for documentation.
There was a problem hiding this comment.
I'm not confident that we can find a common API for all possible lazy loading schemes
Perhaps. But I think we will need some level of abstraction even if it is just knowing where to put our setup call.
That could look like a setupOptionLoc option with a default based on which backend is enabled?
E.g.
setupOptionLoc = mkOption {
type = listOf str; # maybe a non-merging list instead?
default =
if config.pligins.lz-n.enable then
[ "after" ]
else if config.lazy.enable then
[ "config" ]
else
throw "setupOptionLoc cannot be used when no lazyloader is enabled";
defaultText = literalMD "TODO";
}There was a problem hiding this comment.
I was thinking of a function that takes as an input all the required information.... But that will end up in an infinite recursion.
We do need an enumeration of supported backends, but we may not need more than that
7bd6017 to
3d27ea0
Compare
adeebd3 to
9dd8bd4
Compare
lib/neovim-plugin.nix
Outdated
| ++ (lib.optionals (!hasConfigAttrs) [ | ||
| ++ lib.optionals (!hasConfigAttrs) [ | ||
| (lib.optionalAttrs callSetup (setLuaConfig setupCode)) | ||
| ]) | ||
| ++ (lib.optionals hasConfigAttrs [ | ||
| ] |
There was a problem hiding this comment.
How should the !hasConfigAttrs case be handled when lazyloading?
There was a problem hiding this comment.
Looks like we only have one instance of no config attrs, in rustaceanvim, because they use global options for configuration. Seems like something you don't get to really lazy load through a manager and is handled by the plugin itself?
There was a problem hiding this comment.
Certainly for lz-n, there's nothing to lazyload if there's no setup function. lazy.nvim is a bit fancier though.
If we did go down that route, maybe the plugins.*.lazyload option should only exist when hasSetup is true? Although I'm happy for that to be tackled in future work if it is too much for this PR.
f9b74d2 to
b1ba2ac
Compare
MattSturgeon
left a comment
There was a problem hiding this comment.
Looks good. Just last minute discussions
2882658 to
7b581b9
Compare
25efd2e to
a7c13e1
Compare
lib/neovim-plugin.nix
Outdated
| warnings = lib.optional (!config.plugins.lz-n.enable) '' | ||
| You have enabled lazy loading for ${originalName} but have not enabled any lazy loading plugins. | ||
| We will not insert the lua for this plugin and you must handle loading it yourself. | ||
|
|
||
| Currently supported lazy providers: | ||
| - lz-n | ||
| ''; |
There was a problem hiding this comment.
This means that if someone wants to use an unsupported lazy loader they will have warnings for each of their plugins right?
In another PR we should consider adding a global option that will allow to silence the warnings, something like useUnsupportedLazyLoader
There was a problem hiding this comment.
Oh duh, yeah.. I'll move it out
We will support more, might as well properly organize them.
Instead of trying to manage upstream configuration options, just keep using our freeform options so we can do less finicky logic and workarounds.
a7c13e1 to
ebfa0c9
Compare
We don't need to run nvim and see what happens, these are just used for making sure we're generating the config appropriately.
ebfa0c9 to
b752606
Compare
MattSturgeon
left a comment
There was a problem hiding this comment.
Thanks for working on this!
|
@Mergifyio queue |
✅ The pull request has been merged automaticallyDetailsThe pull request has been merged automatically at b752606 |
|
This pull request, with head sha This pull request will be automatically closed by GitHub.As soon as GitHub detects that the sha It is possible for this pull request to remain open if this detection does not happen, this usually happens when a force-push is done on this branch |
Closes #1875 and #2577