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:
@@ -8,6 +8,7 @@ local M = {
|
||||
config = {},
|
||||
}
|
||||
|
||||
---@param windows integer[]
|
||||
local function close_windows(windows)
|
||||
-- Prevent from closing when the win count equals 1 or 2,
|
||||
-- where the win to remove could be the last opened.
|
||||
@@ -23,6 +24,7 @@ local function close_windows(windows)
|
||||
end
|
||||
end
|
||||
|
||||
---@param absolute_path string
|
||||
local function clear_buffer(absolute_path)
|
||||
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 }
|
||||
for _, buf in pairs(bufs) do
|
||||
@@ -44,10 +46,13 @@ local function clear_buffer(absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
---@param cwd string
|
||||
---@return boolean|nil
|
||||
local function remove_dir(cwd)
|
||||
local handle = vim.loop.fs_scandir(cwd)
|
||||
if type(handle) == "string" then
|
||||
return notify.error(handle)
|
||||
notify.error(handle)
|
||||
return
|
||||
end
|
||||
|
||||
while true do
|
||||
@@ -75,20 +80,22 @@ local function remove_dir(cwd)
|
||||
end
|
||||
|
||||
--- Remove a node, notify errors, dispatch events
|
||||
--- @param node table
|
||||
---@param node Node
|
||||
function M.remove(node)
|
||||
local notify_node = notify.render_path(node.absolute_path)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. notify_node)
|
||||
notify.error("Could not remove " .. notify_node)
|
||||
return
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
events._dispatch_will_remove_file(node.absolute_path)
|
||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. notify_node)
|
||||
notify.error("Could not remove " .. notify_node)
|
||||
return
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
@@ -96,6 +103,7 @@ function M.remove(node)
|
||||
notify.info(notify_node .. " was properly removed.")
|
||||
end
|
||||
|
||||
---@param node Node
|
||||
function M.fn(node)
|
||||
if node.name == ".." then
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user