Skip to content
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

Merged
merged 11 commits into from
Dec 10, 2024

Conversation

khaneliman
Copy link
Contributor

Closes #1875 and #2577

@khaneliman khaneliman force-pushed the lazy-complex branch 4 times, most recently from d73d2b6 to 6635837 Compare December 2, 2024 20:27
lib/options.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated
Comment on lines 372 to 378
# 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;
};
};
Copy link
Member

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

Copy link
Contributor Author

@khaneliman khaneliman Dec 4, 2024

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.

Copy link
Member

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";
}

Copy link
Member

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

@khaneliman khaneliman force-pushed the lazy-complex branch 5 times, most recently from 7bd6017 to 3d27ea0 Compare December 5, 2024 15:19
lib/options.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
@khaneliman khaneliman force-pushed the lazy-complex branch 2 times, most recently from adeebd3 to 9dd8bd4 Compare December 5, 2024 18:56
@khaneliman khaneliman changed the title lazy-complex mkNeovimPlugin: add lazyLoad Dec 5, 2024
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
Comment on lines 155 to 158
++ (lib.optionals (!hasConfigAttrs) [
++ lib.optionals (!hasConfigAttrs) [
(lib.optionalAttrs callSetup (setLuaConfig setupCode))
])
++ (lib.optionals hasConfigAttrs [
]
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

lib/neovim-plugin.nix Outdated Show resolved Hide resolved
@khaneliman khaneliman force-pushed the lazy-complex branch 4 times, most recently from f9b74d2 to b1ba2ac Compare December 5, 2024 21:21
Copy link
Member

@MattSturgeon MattSturgeon left a 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

lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
@khaneliman khaneliman force-pushed the lazy-complex branch 4 times, most recently from 25efd2e to a7c13e1 Compare December 10, 2024 15:48
lib/neovim-plugin.nix Outdated Show resolved Hide resolved
lib/options.nix Outdated Show resolved Hide resolved
Comment on lines 177 to 183
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
'';
Copy link
Member

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

Copy link
Contributor Author

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.
We don't need to run nvim and see what happens, these are just used for
making sure we're generating the config appropriately.
Copy link
Member

@GaetanLepage GaetanLepage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !!!

Copy link
Member

@MattSturgeon MattSturgeon left a 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!

@GaetanLepage
Copy link
Member

@Mergifyio queue

Copy link
Contributor

mergify bot commented Dec 10, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at b752606

Copy link
Contributor

mergify bot commented Dec 10, 2024

This pull request, with head sha b752606681ded3f69e99ed568c7075b3578dce48, has been successfully merged with fast-forward by Mergify.

This pull request will be automatically closed by GitHub.

As soon as GitHub detects that the sha b752606681ded3f69e99ed568c7075b3578dce48 is part of the main branch, it will mark this pull request as merged.

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 lazy-complex, this means GitHub will fail to detect the merge.

@mergify mergify bot merged commit b752606 into nix-community:main Dec 10, 2024
4 checks passed
@khaneliman khaneliman deleted the lazy-complex branch December 10, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants