-
-
Notifications
You must be signed in to change notification settings - Fork 638
refactor(#3225): multi instance - move expand actions to nodes #3234
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
Open
Uanela
wants to merge
4
commits into
nvim-tree:master
Choose a base branch
from
Uanela:refactor-modifiers-expand
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−176
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd901f7
wip(explorer): rename :expand to :expand_dir_node and all places usin…
Uanela 7933869
wip: move expand function to directory
Uanela 7481c19
refactor: move expand functionality to node methods
Uanela a192e88
refactor(directory): correctly calling class methods and passing corr…
Uanela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,5 @@ | ||
| local M = {} | ||
|
|
||
| M.collapse = require("nvim-tree.actions.tree.modifiers.collapse") | ||
| M.expand = require("nvim-tree.actions.tree.modifiers.expand") | ||
|
|
||
| function M.setup(opts) | ||
| M.expand.setup(opts) | ||
| end | ||
|
|
||
| return M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| local git_utils = require("nvim-tree.git.utils") | ||
| local icons = require("nvim-tree.renderer.components.devicons") | ||
| local notify = require("nvim-tree.notify") | ||
| local Iterator = require("nvim-tree.iterators.node-iterator") | ||
|
|
||
| local Node = require("nvim-tree.node") | ||
|
|
||
|
|
@@ -167,7 +168,7 @@ function DirectoryNode:expand_or_collapse(toggle_group) | |
| end | ||
|
|
||
| if #self.nodes == 0 then | ||
| self.explorer:expand(self) | ||
| self.explorer:expand_dir_node(self) | ||
| end | ||
|
|
||
| local head_node = self:get_parent_of_group() or self | ||
|
|
@@ -290,4 +291,129 @@ function DirectoryNode:clone(api_nodes) | |
| return clone | ||
| end | ||
|
|
||
| ---@private | ||
| ---@param should_descend fun(expansion_count: integer, node: Node): boolean | ||
| ---@return fun(expansion_count: integer, node: Node): boolean | ||
| function DirectoryNode:limit_folder_discovery(should_descend) | ||
| local MAX_FOLDER_DISCOVERY = self.explorer.opts.actions.expand_all.max_folder_discovery | ||
| return function(expansion_count) | ||
| local should_halt = expansion_count >= MAX_FOLDER_DISCOVERY | ||
| if should_halt then | ||
| notify.warn("expansion iteration was halted after " .. MAX_FOLDER_DISCOVERY .. " discovered folders") | ||
| return false | ||
| end | ||
|
|
||
| return should_descend(expansion_count, self) | ||
| end | ||
| end | ||
|
|
||
| ---@private | ||
| ---@param list string[] | ||
| ---@return table | ||
| local function to_lookup_table(list) | ||
| local table = {} | ||
| for _, element in ipairs(list) do | ||
| table[element] = true | ||
| end | ||
|
|
||
| return table | ||
| end | ||
|
|
||
| ---@private | ||
| ---@param _ integer expansion_count | ||
| ---@return boolean | ||
| function DirectoryNode:descend_until_empty(_) | ||
| local EXCLUDE = to_lookup_table(self.explorer.opts.actions.expand_all.exclude) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again nice, allows dynamic changes to |
||
| local should_exclude = EXCLUDE[self.name] | ||
| return not should_exclude | ||
| end | ||
|
|
||
| ---@private | ||
| ---@param expansion_count integer | ||
| ---@param node Node | ||
| ---@param should_descend fun(expansion_count: integer, node: Node): boolean | ||
| ---@return boolean | ||
| function DirectoryNode:should_expand(expansion_count, node, should_descend) | ||
| local dir = node:as(DirectoryNode) | ||
| if not dir then | ||
| return false | ||
| end | ||
|
|
||
| if not dir.open and should_descend(expansion_count, node) then | ||
| if #node.nodes == 0 then | ||
| self.explorer:expand_dir_node(dir) -- populate node.group_next | ||
| end | ||
|
|
||
| if dir.group_next then | ||
| local expand_next = self:should_expand(expansion_count, dir.group_next, should_descend) | ||
| if expand_next then | ||
| dir.open = true | ||
| end | ||
| return expand_next | ||
| else | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| ---@private | ||
| ---@param should_descend fun(expansion_count: integer, node: Node): boolean | ||
| ---@return fun(node): any | ||
| function DirectoryNode:gen_iterator(should_descend) | ||
| local expansion_count = 0 | ||
|
|
||
| return function(parent) | ||
| if parent.parent and parent.nodes and not parent.open then | ||
| expansion_count = expansion_count + 1 | ||
| parent:expand_dir_node() | ||
| end | ||
|
|
||
| Iterator.builder(parent.nodes) | ||
| :hidden() | ||
| :applier(function(node) | ||
| if DirectoryNode:should_expand(expansion_count, node, should_descend) then | ||
| expansion_count = expansion_count + 1 | ||
| node = node:as(DirectoryNode) | ||
| if node then | ||
| self:expand_dir_node() | ||
| end | ||
| end | ||
| end) | ||
| :recursor(function(node) | ||
| if not should_descend(expansion_count, node) then | ||
| return nil | ||
| end | ||
|
|
||
| if node.group_next then | ||
| return { node.group_next } | ||
| end | ||
|
|
||
| if node.open and node.nodes then | ||
| return node.nodes | ||
| end | ||
|
|
||
| return nil | ||
| end) | ||
| :iterate() | ||
| end | ||
| end | ||
|
|
||
| ---@param expand_opts ApiTreeExpandOpts? | ||
| function DirectoryNode:expand(expand_opts) | ||
| local descend_until_empty_fn = self.descend_until_empty | ||
| local descend_until = self:limit_folder_discovery((expand_opts and expand_opts.expand_until) or descend_until_empty_fn) | ||
| self:gen_iterator(descend_until)(self) | ||
|
|
||
| self.explorer.renderer:draw() | ||
| end | ||
|
|
||
| function DirectoryNode:expand_dir_node() | ||
| local node = self:last_group_node() | ||
| node.open = true | ||
| if #node.nodes == 0 then | ||
| self.explorer:expand_dir_node(node) | ||
| end | ||
| end | ||
|
|
||
| return DirectoryNode | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice one. Reading it here will allow us to dynamically change
actions.expand_all.max_folder_discovery