Skip to content

Conversation

@przepompownia
Copy link
Collaborator

No description provided.

@przepompownia
Copy link
Collaborator Author

I use my custom, simple Lua module lazy loader. In that way nvim-tree isn't setup and no module is loaded before calling function defined in keymap.

It has a drawback: NvimTree* commands definitions are not loaded at that point too.

Rarely, but still, I would like to start using nvim-tree with such command.

I know that direct call to require('nvim-tree.commands').setup() can be not recommended way, but (with this change) it allows to load command definitions without loading modules not used yet.

That setup() logic could exist in plugin/nvim-tree.lua instead.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Normally I'd give dire warnings about lazy loading, predictable ordering and not using API, however you know exactly what you're doing :)

This looks good/safe and won't change anything.

That setup() logic could exist in plugin/nvim-tree.lua instead.

I'm not quite sure what you mean... would that allow you to avoid requiring commands? Would that not load all the modules?

Either way, sounds good. Do you want to just push it?

},
command = function(c)
api.tree.open({ path = c.args })
require("nvim-tree.api").tree.open({ path = c.args })
Copy link
Member

Choose a reason for hiding this comment

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

Initial thought was to use a common function like

local function api()
  require("nvim-tree.api")
end

however that would just obscure things.
The inline require make it really clear what's going on.

@przepompownia
Copy link
Collaborator Author

przepompownia commented Nov 7, 2025

Normally I'd give dire warnings about lazy loading, predictable ordering and not using API, however you know exactly what you're doing :)

This looks good/safe and won't change anything.

That setup() logic could exist in plugin/nvim-tree.lua instead.

I'm not quite sure what you mean... would that allow you to avoid requiring commands? Would that not load all the modules?

Either way, sounds good. Do you want to just push it?

OK, I can test permissions at the git level: here I have no permissions to merge. Regardless if it works, I can then create a PR with commands definitions moved to plugin directory.

Ah, you probably meant pushing plugin approach here 😀

This change seems to be safe to merge separately. Using plugin/ may require discussion on some details, so let me propose it separately.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

All working, many thanks for your contribution!

@alex-courtis alex-courtis merged commit 68c67ad into nvim-tree:master Nov 9, 2025
4 checks passed
@przepompownia przepompownia deleted the lazy-command-setup branch November 9, 2025 12:08
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.

2 participants