Skip to content

feat: smart lazy-loading + no forced setup#115

Merged
dmtrKovalenko merged 10 commits into
dmtrKovalenko:mainfrom
mrcjkb:mj/push-powtynyswwvm
Aug 24, 2025
Merged

feat: smart lazy-loading + no forced setup#115
dmtrKovalenko merged 10 commits into
dmtrKovalenko:mainfrom
mrcjkb:mj/push-powtynyswwvm

Conversation

@mrcjkb
Copy link
Copy Markdown
Contributor

@mrcjkb mrcjkb commented Aug 18, 2025

Closes #114

I've tested this by adding the plugin's nix flake output to my nvim config.

Things done:

  • Split configuration and initialization
  • Refactored configuration to allow you to use both require('fff').setup(config) and vim.g.fff = config.
    The config is validated the first time it is requested internally via require('fff.conf').get().
  • Fixed an attempt to index nil value error when opening the picker.
  • Initialize the plugin lazily. To make it initialize eagerly, set lazy_sync = false in the config.
  • If initializing eagerly, defer until after UIEnter (this is equivalent to initializing on lazy.nvim's VeryLazy event).
  • Create commands in the plugin/ script. The commands require fff's Lua modules lazily, so this has less startup overhead than would be needed to create lazy-loading configurations with lazy.nvim.

@mrcjkb mrcjkb force-pushed the mj/push-powtynyswwvm branch from fb8b6d2 to 1e972f4 Compare August 19, 2025 07:38
Comment thread README.md Outdated
@@ -51,10 +52,10 @@ FFF.nvim requires:
build = "cargo build --release",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
build = "cargo build --release",
build = "cargo build --release",
-- Prevent lazy.nvim from lazy loading plugin
lazy = false,

Would it make sense to add this to the suggested plugin spec?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't use lazy.nvim, so I don't know for sure. But I believe adding keys = ... makes it lazy-load? Not sure if setting lazy = false overrides that?

I could also put the keymap example in a separate code block that uses vim.keymap.set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm I'm also not sure keys would make it lazy load again, even when lazy = false is specified.

At least for default.config.lazy it seems to get overriden by keys according to this page: https://lazy.folke.io/spec/lazy_loading

Copy link
Copy Markdown
Contributor

@jla2000 jla2000 Aug 22, 2025

Choose a reason for hiding this comment

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

Maybe the safe way would really be to set lazy = false and then use vim.keymap.set in a config() function inside the plugin spec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lazy-loading isn't bad. It's just redundant.
But I do think using vim.keymap.set is a better example, as it also works for users of other plugin managers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added an init with vim.keymap.set.
Note: I chose init over config, because if you use config, lazy.nvim won't automatically pass the opts to the setup function.

@mrcjkb mrcjkb force-pushed the mj/push-powtynyswwvm branch from 3f48dbd to c28dfff Compare August 23, 2025 14:08
@dmtrKovalenko
Copy link
Copy Markdown
Owner

dmtrKovalenko commented Aug 23, 2025

Sorry for the long response—I had a very busy week.

I tested it out, and it appears to be working, although the lazy sync never actually started before the picker is open. Perhaps I'm missing something?

Also, I (and I believe most lazy users) prefer setting up the plugin using keys = {} and opts = {} and controlling laziness solely via the lazy property. I understand why we need the lazy_sync property, but if we're lazy-loading the plugin using lazy.nvim, can't we just set lazy_sync to true by default so it starts syncing once it's initialized by lazy?

@mrcjkb mrcjkb force-pushed the mj/push-powtynyswwvm branch from c28dfff to 33a7681 Compare August 23, 2025 19:45
@mrcjkb
Copy link
Copy Markdown
Contributor Author

mrcjkb commented Aug 23, 2025

No problem 😄
I'm not in a rush.

I tested it out, and it appears to be working, although the lazy sync never actually started before the picker is open. Perhaps I'm missing something?

Should be fixed in the latest commit. I tripped over the nil/false duality.

Also, I (and I believe most lazy users) prefer setting up the plugin using keys = {} and opts = {} and controlling laziness solely via the lazy property.

Okay, I've reverted the lazy.nvim example modification to use the keys field again.

I understand why we need the lazy_sync property, but if we're lazy-loading the plugin using lazy.nvim, can't we just set lazy_sync to true by default so it starts syncing once it's initialized by lazy?

I'm not sure how that would work?
If someone configures lazy.nvim to lazy-load the plugin using a keymap or a command, lazy.nvim will trigger the keymap or command, which will result in ensure_initialized being called.

@dmtrKovalenko dmtrKovalenko merged commit 13b855b into dmtrKovalenko:main Aug 24, 2025
7 checks passed
@mrcjkb mrcjkb deleted the mj/push-powtynyswwvm branch August 26, 2025 19:18
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.

feature request: smart lazy-loading

3 participants