From f57d70ac33a3b52920421cadddac1c3757a8b359 Mon Sep 17 00:00:00 2001 From: Simrat Grewal Date: Wed, 17 Aug 2022 16:45:04 -0700 Subject: [PATCH] refactor: Move dfs to utils --- lua/symbols-outline.lua | 14 +------------- lua/symbols-outline/utils/init.lua | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index 89dee7b..09a5823 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -157,18 +157,6 @@ function M._set_all_folded(folded, nodes) _update_lines() end -local function _items_dfs(callback, children) - children = children or M.state.outline_items - - for _, val in ipairs(children) do - callback(val) - - if val.children then - _items_dfs(callback, val.children) - end - end -end - function M._highlight_current_item(winnr) local has_provider = providers.has_provider() @@ -210,7 +198,7 @@ function M._highlight_current_item(winnr) end end - _items_dfs(cb) + utils.items_dfs(cb, M.state.outline_items) _update_lines() diff --git a/lua/symbols-outline/utils/init.lua b/lua/symbols-outline/utils/init.lua index 15c1aae..1b00738 100644 --- a/lua/symbols-outline/utils/init.lua +++ b/lua/symbols-outline/utils/init.lua @@ -38,6 +38,16 @@ function M.debounce(f, delay) end end +function M.items_dfs(callback, children) + for _, val in ipairs(children) do + callback(val) + + if val.children then + M.items_dfs(callback, val.children) + end + end +end + ---Merges a symbol tree recursively, only replacing nodes ---which have changed. This will maintain the folding ---status of any unchanged nodes. @@ -53,17 +63,14 @@ M.merge_items_rec = function(new_node, old_node, index, parent) else for key, _ in pairs(new_node) do if - vim.tbl_contains( - { - 'parent', - 'children', - 'folded', - 'hovered', - 'line_in_outline', - 'hierarchy', - }, - key - ) + vim.tbl_contains({ + 'parent', + 'children', + 'folded', + 'hovered', + 'line_in_outline', + 'hierarchy', + }, key) then goto continue end