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

@@ -6,11 +6,13 @@ local M = {
config = {},
}
---@class Event
local Event = {
_events = {},
}
Event.__index = Event
---@class Watcher
local Watcher = {
_watchers = {},
}
@@ -23,6 +25,8 @@ local FS_EVENT_FLAGS = {
recursive = false,
}
---@param path string
---@return Event|nil
function Event:new(path)
log.line("watcher", "Event:new '%s'", path)
@@ -40,6 +44,7 @@ function Event:new(path)
end
end
---@return boolean
function Event:start()
log.line("watcher", "Event:start '%s'", self._path)
@@ -84,10 +89,12 @@ function Event:start()
return true
end
---@param listener function
function Event:add(listener)
table.insert(self._listeners, listener)
end
---@param listener function
function Event:remove(listener)
utils.array_remove(self._listeners, listener)
if #self._listeners == 0 then
@@ -95,6 +102,7 @@ function Event:remove(listener)
end
end
---@param message string|nil
function Event:destroy(message)
log.line("watcher", "Event:destroy '%s'", self._path)
@@ -115,6 +123,11 @@ function Event:destroy(message)
self.destroyed = true
end
---@param path string
---@param files string[]|nil
---@param callback function
---@param data table
---@return Watcher|nil
function Watcher:new(path, files, callback, data)
log.line("watcher", "Watcher:new '%s' %s", path, vim.inspect(files))
@@ -160,7 +173,7 @@ end
M.Watcher = Watcher
--- Permanently disable watchers and purge all state following a catastrophic error.
--- @param msg string
---@param msg string
function M.disable_watchers(msg)
notify.warn(string.format("Disabling watchers: %s", msg))
M.config.filesystem_watchers.enable = false
@@ -181,8 +194,8 @@ end
--- Windows NT will present directories that cannot be enumerated.
--- Detect these by attempting to start an event monitor.
--- @param path string
--- @return boolean
---@param path string
---@return boolean
function M.is_fs_event_capable(path)
if not utils.is_windows then
return true