chore: add type annotations and resolve LSP warnings (#2555)

* chore: add type annotations to (almost) all functions

* stylua

* Add classes for symlink nodes

* Replace deprecated `@vararg`

* Move node classes to `node` module

* Fix `Symlink*` classes

* add vim and libuv runtime for luals, qualify libuv types

* add scripts/luals-check, not quite ready for CI

* additional nil checks for git/init.lua and git/runner.lua

* additional nil checks for nvim-tree.lua

* wrap vim.cmd-as-a-function calls inside functions

* vim.tbl_filter predicate returns booleans

* Revert "add scripts/luals-check, not quite ready for CI"

This reverts commit c70229cad9.

* Add `MinimalNode` class in `marks` module

* Fix various LSP warnings

* stylua

* Fix `Explorer` class, update related annotations and add necessary checks

* Add missing annotations to `live-filter`

* Add temporary aliases for `uv.*` types

* Resolve remaining LSP warnings

* Revert changes not related to internal types

* Minor adjustments

* Update doc comments style

* Minor adjustments (pt. 2)

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Azad
2023-12-09 01:34:35 +01:00
committed by GitHub
parent 7d1760f892
commit 13f967f8e7
51 changed files with 622 additions and 161 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|nil
---@return Node|nil cloned node
local function clone_node(node)
if not node then
node = core.get_explorer()
@@ -68,19 +69,25 @@ 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
next_node = next_node.group_next
while node and node.group_next do
node = node.group_next
end
return next_node
---@diagnostic disable-next-line: return-type-mismatch -- it can't be nil
return 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 +98,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
@@ -119,6 +127,7 @@ function M.set_target_win()
M.target_winid = id
end
---@param cwd string
local function handle_buf_cwd(cwd)
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
require("nvim-tree.actions.root.change-dir").fn(cwd)
@@ -144,6 +153,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