chore: add type annotations to (almost) all functions

This commit is contained in:
Akmadan23
2023-11-24 12:01:24 +01:00
parent 46e1f776f0
commit fabea3376e
48 changed files with 438 additions and 83 deletions

View File

@@ -13,6 +13,7 @@ local M = {
target_winid = nil,
}
---@return Node|nil
function M.get_node_at_cursor()
if not core.get_explorer() then
return
@@ -34,8 +35,8 @@ function M.get_node_at_cursor()
end
---Create a sanitized partial copy of a node, populating children recursively.
---@param node table
---@return table|nil cloned node
---@param node Node
---@return Node|nil cloned node
local function clone_node(node)
if not node then
node = core.get_explorer()
@@ -68,11 +69,14 @@ local function clone_node(node)
end
---Api.tree.get_nodes
---@return Node[]|nil
function M.get_nodes()
return clone_node(core.get_explorer())
end
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
---@param node Node
---@return Node
function M.get_last_group_node(node)
local next_node = node
while next_node.group_next do
@@ -81,6 +85,8 @@ function M.get_last_group_node(node)
return next_node
end
---@param node Node
---@return Node[]
function M.get_all_nodes_in_group(node)
local next_node = utils.get_parent_of_group(node)
local nodes = {}
@@ -91,6 +97,7 @@ function M.get_all_nodes_in_group(node)
return nodes
end
---@param node Node
function M.expand_or_collapse(node)
if node.has_children then
node.has_children = false
@@ -144,6 +151,11 @@ local function should_hijack_current_buf()
return should_hijack_dir or should_hijack_unnamed
end
---@param prompt_input string
---@param prompt_select string
---@param items_short string[]
---@param items_long string[]
---@param callback fun(item_short: string)
function M.prompt(prompt_input, prompt_select, items_short, items_long, callback)
local function format_item(short)
for i, s in ipairs(items_short) do