-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
mkNeovimPlugin: add lazyLoad with lz-n support #2602
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should the !hasConfigAttrs
case be handled when lazyloading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
2f8a47a
to
2882658
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
@Mergifyio queue |
✅ The pull request has been merged automaticallyThe 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