-
Notifications
You must be signed in to change notification settings - Fork 255
refactor(filesystem): fix recursive expand of nodes #957
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0407dbf
fix: Pass callback to toggle_directory to notify about async results
ghostbuster91 df45216
Extract methods for better readability
ghostbuster91 f3ac4a9
fix: Handle correctly recursive traversals when deep strategy used
ghostbuster91 fea2e5b
Rewrite recursive expand to use plenary.async
ghostbuster91 e534a34
Recursively load files from filesystem
ghostbuster91 e448258
Remove unused variable
ghostbuster91 714ea7b
Change is_loaded to loaded
ghostbuster91 b5a7224
Fix using multiple fs calls to scan the same directory
ghostbuster91 a0d6cb3
Move rendere.save_pos level up so it won't be called multiple times
ghostbuster91 3da0ba2
Fix after rename
ghostbuster91 c8ff77a
Extract node_expander and restore common/command interface
ghostbuster91 280b224
Move default value to filesystem/commands
ghostbuster91 ced3d8d
Rename expander to prefetcher and add method docs
ghostbuster91 2db83a6
Simplify algorithm
ghostbuster91 8dc93ba
Refactor: Use async function in async stack
ghostbuster91 722aa3d
Refactor: Simplify starting multiple async tasks
ghostbuster91 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 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
local log = require("neo-tree.log") | ||
|
||
local M = {} | ||
|
||
--- Recursively expand all loaded nodes under the given node | ||
--- returns table with all discovered nodes that need to be loaded | ||
---@param node table a node to expand | ||
---@param state table current state of the source | ||
---@return table discovered nodes that need to be loaded | ||
local function expand_loaded(node, state, node_expander) | ||
local function rec(current_node, to_load) | ||
if node_expander.should_prefetch(current_node) then | ||
log.trace("Node " .. current_node:get_id() .. "not loaded, saving for later") | ||
table.insert(to_load, current_node) | ||
else | ||
if not current_node:is_expanded() then | ||
current_node:expand() | ||
state.explicitly_opened_directories[current_node:get_id()] = true | ||
end | ||
local children = state.tree:get_nodes(current_node:get_id()) | ||
log.debug("Expanding childrens of " .. current_node:get_id()) | ||
for _, child in ipairs(children) do | ||
if child.type == "directory" then | ||
rec(child, to_load) | ||
else | ||
log.trace("Child: " .. child.name .. " is not a directory, skipping") | ||
end | ||
end | ||
end | ||
end | ||
|
||
local to_load = {} | ||
rec(node, to_load) | ||
return to_load | ||
end | ||
|
||
--- Recursively expands all nodes under the given node | ||
--- loading nodes if necessary. | ||
--- async method | ||
---@param node table a node to expand | ||
---@param state table current state of the source | ||
local function expand_and_load(node, state, node_expander) | ||
local function rec(to_load, progress) | ||
local to_load_current = expand_loaded(node, state, node_expander) | ||
for _,v in ipairs(to_load_current) do | ||
table.insert(to_load, v) | ||
end | ||
if progress <= #to_load then | ||
M.expand_directory_recursively(state, to_load[progress], node_expander) | ||
rec(to_load, progress + 1) | ||
end | ||
end | ||
rec({}, 1) | ||
end | ||
|
||
--- Expands given node recursively loading all descendant nodes if needed | ||
--- async method | ||
---@param state table current state of the source | ||
---@param node table a node to expand | ||
M.expand_directory_recursively = function(state, node, node_expander) | ||
log.debug("Expanding directory " .. node:get_id()) | ||
if node.type ~= "directory" then | ||
return | ||
end | ||
state.explicitly_opened_directories = state.explicitly_opened_directories or {} | ||
if node_expander.should_prefetch(node) then | ||
local id = node:get_id() | ||
state.explicitly_opened_directories[id] = true | ||
node_expander.prefetch(state, node) | ||
expand_loaded(node, state, node_expander) | ||
else | ||
expand_and_load(node, state, node_expander) | ||
end | ||
end | ||
|
||
M.default_expander = { | ||
prefetch = function (state, node) | ||
log.debug("Default expander prefetch does nothing") | ||
end, | ||
should_prefetch = function (node) | ||
return false | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.