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

@@ -29,6 +29,10 @@ local WATCHED_FILES = {
"index", -- staging area
}
--- @param toplevel string|nil
--- @param path string|nil
--- @param project table
--- @param git_status table|nil
local function reload_git_status(toplevel, path, project, git_status)
if path then
for p in pairs(project.files) do
@@ -118,6 +122,7 @@ function M.reload_project(toplevel, path, callback)
end
--- Retrieve a known project
--- @param toplevel string|nil
--- @return table|nil project
function M.get_project(toplevel)
return M._projects_by_toplevel[toplevel]

View File

@@ -2,12 +2,16 @@ local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local notify = require "nvim-tree.notify"
---@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)
-- replacing slashes if on windows
if vim.fn.has "win32" == 1 then
@@ -18,6 +22,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 +54,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_pipe_t
---@param stderr_handle 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 +73,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 +81,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 +168,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)

View File

@@ -6,9 +6,9 @@ local M = {
}
--- Retrieve the git toplevel directory
--- @param cwd string path
--- @return string|nil toplevel absolute path
--- @return string|nil git_dir absolute path
---@param cwd string path
---@return string|nil toplevel absolute path
---@return string|nil git_dir absolute path
function M.get_toplevel(cwd)
local profile = log.profile_start("git toplevel git_dir %s", cwd)
@@ -60,6 +60,8 @@ end
local untracked = {}
---@param cwd string
---@return string|nil
function M.should_show_untracked(cwd)
if untracked[cwd] ~= nil then
return untracked[cwd]
@@ -85,6 +87,9 @@ local function nil_insert(t, k)
return t
end
---@param status table
---@param cwd string|nil
---@return table
function M.file_status_to_dir_status(status, cwd)
local direct = {}
for p, s in pairs(status) do