-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
lib/neovim-plugin: Add lazyLoad option to plugins #1875
Conversation
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.
Just my initial thoughts. Again, thanks for working on this!
To keep things organized i am going to wait for PR #1874 to be stabilised to keep working on this. |
Probably better to have our defaults set with That's only a guideline though, not a rule. There may be times where a default is so sensible that it makes sense not to use |
Seems like #1874 got morgen! I am hyped for this feature 🙌🏻 |
Now that #1874 has been merged I am going to rework this PR to work with that implementation. While working on #1874 I discovered some flaws in the draft implementation of this PR, that need to be addressed. I am also going to integrate with the new helpers implementation from #1948. It also would be nice to integrate |
I refactored the |
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 know this is still a draft, so some of my feedback may be irrelevant. But here's some early feedback in the hopes it helps.
Thank you for your continued efforts!
@@ -47,6 +48,8 @@ let | |||
dontRun ? false, | |||
}: | |||
lib.optionalString (!dontRun) '' | |||
ln -s ${derivation} $out/${name} |
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 understand this is a temporary debugging change, but I think this highlights another reason we should probably move back to using linkFarm
instead of a custom derivation, even if it's still grouped on a per-test-file basis.
#1989 does this, among other things.
We could of course add the package being tested to passthru
manually, but linkFarm
does that for us.
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.
The old implementation also didn't work for this kind of test. Because the linkFarm was of all the tests.
With this change I can build a specific test and run that nixvim instance to test functionallity inside neovim.
Maybe I missed a better way to achieve this...
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.
With this change I can build a specific test and run that nixvim instance to test functionality inside neovim.
I think what we want here is to be able to build a test's passthru to debug it. If the test fails, that's because it can't be built.
If I understand passthru correctly, it would allow us to bypass building the test derivation and instead use the derivation that was being tested.
In the case of a linkFarm we'd probably be building a passthru of a passthru, russian doll style.
This is something we ought to tackle in another PR, especially as our test infrastructure is somewhat in flux currently: #2015 #1989 #1986 etc
I just pushed an implementation for lazy loading with 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.
Minor suggestions and attempts to understand the changes 🙂
(lib.removeAttrs (extraConfig cfg) [ | ||
"extraConfigLua" | ||
"extraConfigLuaPre" | ||
]) |
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 isn't a robust solution, we really need something like #1876 so that we can assign plugin-config to an option and then decide here how to use that option.
The problem is we're assuming extraConfig
returns a "plain" attrset, instead of something like a mkIf
, mkOverride
, mkMerge
, etc.
It's also kinda "pulling the rug out" from the module definition, which is expecting a config definition to actually add a definition to the respective option.
If we have an intermediate, plugin-specific option, this is more transparent and also exposes better hooks to end-users.
if cfg.lazyLoad.after == null then | ||
mkFn ( | ||
(extraConfig cfg).extraConfigLuaPre or "" | ||
+ optionalString callSetup ''require('${luaName}')${setup}(${ | ||
optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings) | ||
}) '' | ||
+ (extraConfig cfg).extraConfigLua or "" | ||
) |
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.
Could this be the after
option's default
, instead of null
? This if then else
is effectively setting a default.
Don't mind too much if it is set with default
in mkOption, or if we use lib.mkDefault
in a config definition. We should probably also have a defaultText = literalExpression ""
too, for transparency.
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 guess this is more complex because mkLazyLoadOption
isn't given an actual option path, so it can't (truly) know which extraConfigLua
definitions are being used, etc. Same for luaName
, setup
, etc.
We can still implement it as a ${namespace}.${name}.lazyload.after = mkDefault (mkFn "")
, we just would struggle to document this in defaultText
originalName, | ||
lazyLoadDefaults ? { }, |
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.
originalName, | |
lazyLoadDefaults ? { }, | |
pluginName, | |
defaults ? { }, |
@@ -47,6 +48,8 @@ let | |||
dontRun ? false, | |||
}: | |||
lib.optionalString (!dontRun) '' | |||
ln -s ${derivation} $out/${name} |
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.
With this change I can build a specific test and run that nixvim instance to test functionality inside neovim.
I think what we want here is to be able to build a test's passthru to debug it. If the test fails, that's because it can't be built.
If I understand passthru correctly, it would allow us to bypass building the test derivation and instead use the derivation that was being tested.
In the case of a linkFarm we'd probably be building a passthru of a passthru, russian doll style.
This is something we ought to tackle in another PR, especially as our test infrastructure is somewhat in flux currently: #2015 #1989 #1986 etc
@@ -43,9 +43,14 @@ with lib; | |||
extraPackages ? [ ], | |||
callSetup ? true, | |||
installPackage ? true, | |||
# lazyLoad | |||
allowLazyLoad ? true, | |||
packageName ? originalName, # Name of the package folder created in {runtimepath}/pack/start or {runtimepath}/pack/opt |
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.
Is this not the same as luaName
?
optionalPlugin = | ||
x: | ||
if isColorscheme then x else ((if x ? plugin then x else { plugin = x; }) // { optional = true; }); | ||
mkFn = str: if str != "" then "function()\n" + str + "end" else null; |
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.
mkFn
feels like an over-abstraction
# Lazy loading with lz-n | ||
(mkIf (lazyLoaded && config.plugins.lz-n.enable) (mkMerge [ |
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 don't think it actually matters whether lz-n
is enabled; we can define the config either way, it'll just have no effect, right?
We should probably assert somewhere that a supported lazy loading backend is enabled if the user has enabled lazyloading globally though.
I'm not sure. The stuff in I don't think the stuff in |
This PR is the second split of PR #1866, it works on a solution for the issue #421.
This PR depends on PR #1874.
All suggestions from the original PR are included.
Design description
The idea is to automatically create
lazyLoad
option for all plugins that are defined withmkNeovimPlugin
.lazyLoad
is conformed by triggers (e.g. filetype, event, key, command) and actions (e.g. functions to run before/after loading the plugin).mkNeovimPlugin
would also generate default values for some of these options (e.g. the setup).Plugin maintainers can decide to not create the
lazyLoad
option, by settingallowLazyLoading
to false when defining the plguin.Plugin maintainers can provide sensible default values to
lazyLoad
when defining a plugin. For example, if definingtelescope.nvim
, setTelescope
as a command trigger. Also defining a custom setup function if they are settingcallSetup
as false.Finnally users can :
mkForce
) on a per-plugin basis.Progress
mkLazyLoadOption
to generate lazyLoad options for plugins.mkNeovimPlugin
.mkVimPlugin
.