style: added proper types to process

This commit is contained in:
Folke Lemaitre 2023-02-15 17:07:57 +01:00
parent c249ea376b
commit 78264fb935
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 9 additions and 6 deletions

View File

@ -2,7 +2,7 @@ local Config = require("lazy.core.config")
local M = {} local M = {}
---@type table<vim.loop.Process, true> ---@type table<uv.uv_process_t, true>
M.running = {} M.running = {}
M.signals = { M.signals = {
@ -57,28 +57,31 @@ function M.spawn(cmd, opts)
opts = opts or {} opts = opts or {}
opts.timeout = opts.timeout or (Config.options.git and Config.options.git.timeout * 1000) opts.timeout = opts.timeout or (Config.options.git and Config.options.git.timeout * 1000)
---@type table<string, string>
local env = vim.tbl_extend("force", { local env = vim.tbl_extend("force", {
GIT_SSH_COMMAND = "ssh -oBatchMode=yes", GIT_SSH_COMMAND = "ssh -oBatchMode=yes",
}, uv.os_environ(), opts.env or {}) }, uv.os_environ(), opts.env or {})
env.GIT_DIR = nil env.GIT_DIR = nil
env.GIT_TERMINAL_PROMPT = "0" env.GIT_TERMINAL_PROMPT = "0"
---@type string[]
local env_flat = {} local env_flat = {}
for k, v in pairs(env) do for k, v in pairs(env) do
env_flat[#env_flat + 1] = k .. "=" .. v env_flat[#env_flat + 1] = k .. "=" .. v
end end
local stdout = uv.new_pipe() local stdout = assert(uv.new_pipe())
local stderr = uv.new_pipe() local stderr = assert(uv.new_pipe())
local output = "" local output = ""
---@type vim.loop.Process ---@type uv.uv_process_t
local handle = nil local handle = nil
---@type uv.uv_timer_t
local timeout local timeout
local killed = false local killed = false
if opts.timeout then if opts.timeout then
timeout = uv.new_timer() timeout = assert(uv.new_timer())
timeout:start(opts.timeout, 0, function() timeout:start(opts.timeout, 0, function()
if M.kill(handle) then if M.kill(handle) then
killed = true killed = true
@ -100,7 +103,7 @@ function M.spawn(cmd, opts)
handle:close() handle:close()
stdout:close() stdout:close()
stderr:close() stderr:close()
local check = uv.new_check() local check = assert(uv.new_check())
check:start(function() check:start(function()
if not stdout:is_closing() or not stderr:is_closing() then if not stdout:is_closing() or not stderr:is_closing() then
return return