feat: handle api legacy calls and update signature

This commit is contained in:
Rami Elwan 2025-05-18 09:43:44 +02:00
parent eab4fe5fed
commit df1f535e20
2 changed files with 17 additions and 4 deletions

View File

@ -23,9 +23,18 @@ local function buf_match()
end
end
---@param node Node
---@param keep_buffers boolean
function M.fn(node, keep_buffers)
---@param node Node|boolean|nil legacy -> opts.keep_buffers
---@param opts ApiTreeCollapseAllOpts|nil
function M.fn(node, opts)
-- legacy arguments
if type(node) == "boolean" then
opts = {
keep_buffers = node,
}
node = nil
end
opts = opts or {}
local explorer = core.get_explorer()
if not explorer then
return
@ -51,7 +60,7 @@ function M.fn(node, keep_buffers)
:applier(function(n)
local dir = n:as(DirectoryNode)
if dir then
dir.open = keep_buffers and matches(dir.absolute_path)
dir.open = opts.keep_buffers and matches(dir.absolute_path)
end
end)
:recursor(function(n)

View File

@ -182,6 +182,10 @@ Api.tree.get_nodes = wrap_explorer("get_nodes")
Api.tree.find_file = wrap(actions.tree.find_file.fn)
Api.tree.search_node = wrap(actions.finders.search_node.fn)
---@class ApiTreeCollapseAllOpts
---@field keep_buffers boolean|nil default false
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.fn)
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand_all.fn)
Api.tree.toggle_enable_filters = wrap_explorer_member("filters", "toggle")