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:
@@ -2,13 +2,26 @@ local log = require "nvim-tree.log"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
-- TODO add "${3rd}/luv/library" to "workspace.library"
|
||||
---@class uv.uv_handle_t: table
|
||||
---@class uv.uv_stream_t: uv.uv_handle_t
|
||||
---@class uv.uv_pipe_t: uv.uv_stream_t
|
||||
|
||||
---@class Runner
|
||||
local Runner = {}
|
||||
Runner.__index = Runner
|
||||
|
||||
local timeouts = 0
|
||||
local MAX_TIMEOUTS = 5
|
||||
|
||||
---@private
|
||||
---@param status string
|
||||
---@param path string|nil
|
||||
function Runner:_parse_status_output(status, path)
|
||||
if not path then
|
||||
return
|
||||
end
|
||||
|
||||
-- replacing slashes if on windows
|
||||
if vim.fn.has "win32" == 1 then
|
||||
path = path:gsub("/", "\\")
|
||||
@@ -18,6 +31,10 @@ function Runner:_parse_status_output(status, path)
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param prev_output string
|
||||
---@param incoming string
|
||||
---@return string
|
||||
function Runner:_handle_incoming_data(prev_output, incoming)
|
||||
if incoming and utils.str_find(incoming, "\n") then
|
||||
local prev = prev_output .. incoming
|
||||
@@ -46,12 +63,15 @@ function Runner:_handle_incoming_data(prev_output, incoming)
|
||||
end
|
||||
|
||||
for line in prev_output:gmatch "[^\n]*\n" do
|
||||
self._parse_status_output(line)
|
||||
self:_parse_status_output(line)
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
---@param stdout_handle uv.uv_pipe_t
|
||||
---@param stderr_handle uv.uv_pipe_t
|
||||
---@return table
|
||||
function Runner:_getopts(stdout_handle, stderr_handle)
|
||||
local untracked = self.list_untracked and "-u" or nil
|
||||
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
|
||||
@@ -62,6 +82,7 @@ function Runner:_getopts(stdout_handle, stderr_handle)
|
||||
}
|
||||
end
|
||||
|
||||
---@param output string
|
||||
function Runner:_log_raw_output(output)
|
||||
if log.enabled "git" and output and type(output) == "string" then
|
||||
log.raw("git", "%s", output)
|
||||
@@ -69,12 +90,17 @@ function Runner:_log_raw_output(output)
|
||||
end
|
||||
end
|
||||
|
||||
---@param callback function|nil
|
||||
function Runner:_run_git_job(callback)
|
||||
local handle, pid
|
||||
local stdout = vim.loop.new_pipe(false)
|
||||
local stderr = vim.loop.new_pipe(false)
|
||||
local timer = vim.loop.new_timer()
|
||||
|
||||
if stdout == nil or stderr == nil or timer == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local function on_finish(rc)
|
||||
self.rc = rc or 0
|
||||
if timer:is_closing() or stdout:is_closing() or stderr:is_closing() or (handle and handle:is_closing()) then
|
||||
@@ -151,6 +177,7 @@ function Runner:_wait()
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts table
|
||||
function Runner:_finalise(opts)
|
||||
if self.rc == -1 then
|
||||
log.line("git", "job timed out %s %s", opts.toplevel, opts.path)
|
||||
@@ -167,9 +194,9 @@ function Runner:_finalise(opts)
|
||||
end
|
||||
|
||||
--- Runs a git process, which will be killed if it takes more than timeout which defaults to 400ms
|
||||
--- @param opts table
|
||||
--- @param callback function|nil executed passing return when complete
|
||||
--- @return table|nil status by absolute path, nil if callback present
|
||||
---@param opts table
|
||||
---@param callback function|nil executed passing return when complete
|
||||
---@return table|nil status by absolute path, nil if callback present
|
||||
function Runner.run(opts, callback)
|
||||
local self = setmetatable({
|
||||
toplevel = opts.toplevel,
|
||||
|
||||
Reference in New Issue
Block a user