-
-
Notifications
You must be signed in to change notification settings - Fork 633
feat(#2789): add optional function expand_until to api.tree.expand_all and api.node.expand #3166
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
lua/nvim-tree/api.lua
Outdated
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all) | ||
|
||
Api.tree.toggle_descend_until = wrap_node(function(node, descend_until) |
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.
note: this is actually what I would like to achieve in the end. The fixededit
part is wrong as nodes are not getting collapsed after hitting enter for the second time. Can you advise?
question: how should the end user api look like?
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 will be very useful, however it needs a bit of thought.
Can we please do this in a future PR? The functionality for the API expands is working and we can merge that now.
What should it look like? This isn't something the user should have to do; it should be core functionality.
It could go into node.open.edit
, as a new member of NodeEditOpts
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.
Doing it in a separate PR makes perfect sense 👍
Thanks for getting back to this one @ghostbuster91 My time is limited, however I will get to reviewing next weekend. FYI the nightly CI failure has been resolved on master: #3167 |
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.
Looking good, let's merge the expand functionality now.
Please:
- revert the ordering changes in
api.lua
- rename
ApiTreeExpandOpts
- rename
expand_until
- revert
toggle_descend_until
for a future PR - add :help for
-
api.tree.expand_all
-
api.node.expand
-
lua/nvim-tree/api.lua
Outdated
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all) | ||
|
||
Api.tree.toggle_descend_until = wrap_node(function(node, descend_until) |
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 will be very useful, however it needs a bit of thought.
Can we please do this in a future PR? The functionality for the API expands is working and we can merge that now.
What should it look like? This isn't something the user should have to do; it should be core functionality.
It could go into node.open.edit
, as a new member of NodeEditOpts
All comments have been addressed. Ready for the final review |
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.
We're getting really close.
- Expand all does not expand grouped nodes
- expand.lua expects
descend_until
from the user, notexpand_until
- Help needs to document
expand_until
; I'll do that one -
max_folder_discovery
is not obeyed when usingexpand_until
api.tree.expand_all
with no expand_until

api.tree.expand
on node with no expand_until

This doesn't apply:
---@type ApiTreeExpandOpts
local expand_all_opts = {
expand_until = function(i, node)
print(i .. " " .. node.name)
return node.name ~= "stop" and node.name ~= ".git" and node.name ~= "7"
end
}
tree.expand_all({node}, {opts}) *nvim-tree-api.tree.expand_all()*
Recursively expand all nodes under the tree root or specified folder.
Parameters: ~
• {node} (Node|nil) folder
• {opts} (ApiTreeExpandOpts) optional parameters
Options: ~
• {expand_until} ((fun(expansion_count: integer, node: Node?): boolean)?)
Return true if {node} should be expanded.
{expansion_count} is the total number of folders expanded. node.expand({node}, {opts}) *nvim-tree-api.node.expand()*
Recursively expand all nodes under a directory or a file's parent
directory.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (ApiTreeExpandOpts) optional parameters
Options: ~
• {expand_until} ((fun(expansion_count: integer, node: Node?): boolean)?)
Return true if {node} should be expanded.
{expansion_count} is the total number of folders expanded. |
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.
Many thanks for all your work on this one @ghostbuster91 , it's not been easy.
In the interest of speed, I'm applying the nits and merging.
@@ -72,12 +129,13 @@ local function gen_iterator() | |||
end |
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 max folder discovery test above does not appear to be necessary as limit_folder_discovery
does the job.
Commenting this out results in the correct number of folders being expanded, just no message.
Having the same test twice in two locations is fragile and unclear.
Proposal: limit_folder_discovery
prints the warning and gen_iterator
's function returns nothing.
thanks @alex-courtis for the reviews and tests. I appreciate the effort. |
This closes #2789
It took me a while but here I am :) I decided to create a fresh one as it was easier then resolving conflicts on the old one.
For now bare minimum of the changes that makes it work. Once we agree how the api will look like I will add docs following what we did in #2790