-
-
Notifications
You must be signed in to change notification settings - Fork 635
feat: load command definitions at nvim startup #3211
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
Conversation
plugin directory
|
It depends on #3210. Initially I wanted to move most of I'm not sure if the commit should be labelled as I didn't check yet if it's "setup-safe" - at the first glance it looks like |
| @@ -0,0 +1 @@ | |||
| require("nvim-tree.commands").setup() | |||
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.
When we finally get around to tidying the API a similar approach can be used.
|
This all looks great, it works. Looking at some other plugins, they all have one shot initialisation guards, likely to handle re-sourcing your config. This one uses a lua local: https://github.com/MeanderingProgrammer/render-markdown.nvim/blob/main/plugin/render-markdown.lua A I'm inclined to go with the the |
|
Thinking about other things that can go in here, not necessarily today:
Don't mind me, I'm just brainstorming. |
|
Don't forget that you're an nvim-tree team member with write permissions - you are able to push branches. |
|
I'm still confused about the scope of privileges but, indeed, pushing non-master branch here turns out to work for me, so I can create PR's from this original repo instead of my fork. The markdown plugin example does not defer loading a few modules (which may contain further The (still not moved to Nvim) lspconfig command definitions are loaded lazily as expected (and what it might look like here if there were no dependence on api). |
Yeah, that one's not cool. It loads the world.
They get away with it as vim's APIs are just _meta shells. Doesn't work for us or other plugins. |
|
What do you think about: if vim.g.NvimTreeLoaded ~= nil then
return
end
vim.g.NvimTreeLoaded = 1to match Alternatively, |
It's a feature. Maybe "load command definitions at vim startup" |
plugin directory
FYI. I kept this guard in mind and looked into plugins used by me before creating this PR. Only part of them uses it. I would need an example to be convinced that we really need this. |
Yeah, fair enough. commands.setup is idempotent due to the We'll have to be mindful of this in the future. Do you have any other work you'd like to do around startup and loading? |
In practice I have the user commands available without workarounds and with lazy loading. I don't want to interfere in the decision about whether to keep commands.get() available by API (maybe some users use it) or not (in that case we would move its logic to Thank you for merging! |
Please always question decisions, your input is valuable. The legendary plugin folks were pretty specific about getting keymaps #1858 and less specific about commands #2076 They are used however I'm open to anything that doesn't break existing API. |
|
The only side note: Nvim commands cannot be namespaced (like augroups). It seems that on the Nvim side we can only filter the result of |
|
local commands = vim.api.nvim_get_commands({});
for k, c in vim.spairs(commands) do
print(k .. "\t" .. c.script_id)
endHopefully they build this out; namespace or some other plugin id would be valuable. |
|
Regardless of that I don't suggest relying on that, you shown that (unlike I said) in your example |
This change ensures that commands are defined even if most modules are loaded as late as possible.