mirror of https://github.com/neovim/neovim.git
Merge 91aa36cf10
into 5e98439f6d
This commit is contained in:
commit
ec3ea47be9
|
@ -1780,15 +1780,15 @@ vim.system({cmd}, {opts}, {on_exit}) *vim.system()*
|
|||
will be written to stdin and closed. Defaults to `false`.
|
||||
• stdout: (boolean|function) Handle output from stdout.
|
||||
When passed as a function must have the signature
|
||||
`fun(err: string, data: string)`. Defaults to `true`
|
||||
`fun(err: string, data: string)`. Defaults to `true`.
|
||||
• stderr: (boolean|function) Handle output from stderr.
|
||||
When passed as a function must have the signature
|
||||
`fun(err: string, data: string)`. Defaults to `true`.
|
||||
• text: (boolean) Handle stdout and stderr as text.
|
||||
Replaces `\r\n` with `\n`.
|
||||
• timeout: (integer) Run the command with a time limit.
|
||||
Upon timeout the process is sent the TERM signal (15) and
|
||||
the exit code is set to 124.
|
||||
• timeout: (integer) Run the command with a time limit
|
||||
(given in milliseconds). Upon timeout the process is sent
|
||||
the TERM signal (15) and the exit code is set to 124.
|
||||
• detach: (boolean) If true, spawn the child process in a
|
||||
detached state - this will make it a process group
|
||||
leader, and will effectively enable the child to keep
|
||||
|
@ -1805,15 +1805,16 @@ vim.system({cmd}, {opts}, {on_exit}) *vim.system()*
|
|||
(`vim.SystemObj`) Object with the fields:
|
||||
• cmd (string[]) Command name and args
|
||||
• pid (integer) Process ID
|
||||
• wait (fun(timeout: integer|nil): SystemCompleted) Wait for the
|
||||
process to complete. Upon timeout the process is sent the KILL
|
||||
signal (9) and the exit code is set to 124. Cannot be called in
|
||||
|api-fast|.
|
||||
• SystemCompleted is an object with the fields:
|
||||
• code: (integer)
|
||||
• signal: (integer)
|
||||
• stdout: (string), nil if stdout argument is passed
|
||||
• stderr: (string), nil if stderr argument is passed
|
||||
• wait (fun(timeout: integer|nil): vim.SystemCompleted) Wait for the
|
||||
process to complete, for {timeout} milliseconds (if {timeout} is
|
||||
given) or the timeout specified in {opts}. Upon timeout the process
|
||||
is sent the TERM signal (15) and the exit code is set to 124. Cannot
|
||||
be called in |api-fast|.
|
||||
• vim.SystemCompleted is an object with the fields:
|
||||
• code: (integer)
|
||||
• signal: (integer)
|
||||
• stdout: (string), nil if stdout argument is passed
|
||||
• stderr: (string), nil if stderr argument is passed
|
||||
• kill (fun(signal: integer|string))
|
||||
• write (fun(data: string|nil)) Requires `stdin=true`. Pass `nil` to
|
||||
close the stream.
|
||||
|
|
|
@ -105,13 +105,13 @@ vim.log = {
|
|||
--- and closed. Defaults to `false`.
|
||||
--- - stdout: (boolean|function)
|
||||
--- Handle output from stdout. When passed as a function must have the signature `fun(err: string, data: string)`.
|
||||
--- Defaults to `true`
|
||||
--- Defaults to `true`.
|
||||
--- - stderr: (boolean|function)
|
||||
--- Handle output from stderr. When passed as a function must have the signature `fun(err: string, data: string)`.
|
||||
--- Defaults to `true`.
|
||||
--- - text: (boolean) Handle stdout and stderr as text. Replaces `\r\n` with `\n`.
|
||||
--- - timeout: (integer) Run the command with a time limit. Upon timeout the process is sent the
|
||||
--- TERM signal (15) and the exit code is set to 124.
|
||||
--- - timeout: (integer) Run the command with a time limit (given in milliseconds).
|
||||
--- Upon timeout the process is sent the TERM signal (15) and the exit code is set to 124.
|
||||
--- - detach: (boolean) If true, spawn the child process in a detached state - this will make it
|
||||
--- a process group leader, and will effectively enable the child to keep running after the
|
||||
--- parent exits. Note that the child process will still keep the parent's event loop alive
|
||||
|
@ -123,14 +123,15 @@ vim.log = {
|
|||
--- @return vim.SystemObj Object with the fields:
|
||||
--- - cmd (string[]) Command name and args
|
||||
--- - pid (integer) Process ID
|
||||
--- - wait (fun(timeout: integer|nil): SystemCompleted) Wait for the process to complete. Upon
|
||||
--- timeout the process is sent the KILL signal (9) and the exit code is set to 124. Cannot
|
||||
--- be called in |api-fast|.
|
||||
--- - SystemCompleted is an object with the fields:
|
||||
--- - code: (integer)
|
||||
--- - signal: (integer)
|
||||
--- - stdout: (string), nil if stdout argument is passed
|
||||
--- - stderr: (string), nil if stderr argument is passed
|
||||
--- - wait (fun(timeout: integer|nil): vim.SystemCompleted) Wait for the process to complete,
|
||||
--- for {timeout} milliseconds (if {timeout} is given) or the timeout specified in {opts}.
|
||||
--- Upon timeout the process is sent the TERM signal (15) and the exit code is set to 124.
|
||||
--- Cannot be called in |api-fast|.
|
||||
--- - vim.SystemCompleted is an object with the fields:
|
||||
--- - code: (integer)
|
||||
--- - signal: (integer)
|
||||
--- - stdout: (string), nil if stdout argument is passed
|
||||
--- - stderr: (string), nil if stderr argument is passed
|
||||
--- - kill (fun(signal: integer|string))
|
||||
--- - write (fun(data: string|nil)) Requires `stdin=true`. Pass `nil` to close the stream.
|
||||
--- - is_closing (fun(): boolean)
|
||||
|
|
|
@ -90,19 +90,24 @@ end
|
|||
|
||||
local MAX_TIMEOUT = 2 ^ 31
|
||||
|
||||
--- @param timeout? integer
|
||||
--- @param timeout? integer timeout (in milliseconds), must be >= 0.
|
||||
--- @return vim.SystemCompleted
|
||||
function SystemObj:wait(timeout)
|
||||
local state = self._state
|
||||
|
||||
local done = vim.wait(timeout or state.timeout or MAX_TIMEOUT, function()
|
||||
-- If timeout == 0, vim.wait() will return immediately and uv timer won't schedule on_exit()
|
||||
-- in which state.result will be set
|
||||
timeout = math.max(1, timeout or state.timeout or MAX_TIMEOUT)
|
||||
|
||||
local done = vim.wait(timeout, function()
|
||||
return state.result ~= nil
|
||||
end, nil, true)
|
||||
|
||||
if not done then
|
||||
-- Send sigkill since this cannot be caught
|
||||
self:_timeout(SIG.KILL)
|
||||
vim.wait(timeout or state.timeout or MAX_TIMEOUT, function()
|
||||
-- Send SIGTERM since this cannot be caught
|
||||
self:_timeout(SIG.TERM)
|
||||
-- wait a bit more until state.result is set
|
||||
vim.wait(timeout, function()
|
||||
return state.result ~= nil
|
||||
end, nil, true)
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ describe('vim.system', function()
|
|||
it('supports timeout', function()
|
||||
eq({
|
||||
code = 124,
|
||||
signal = 15,
|
||||
signal = 15, -- SIGTERM
|
||||
stdout = '',
|
||||
stderr = '',
|
||||
}, system({ 'sleep', '10' }, { timeout = 1000 }))
|
||||
|
@ -83,6 +83,18 @@ describe('vim.system', function()
|
|||
end)
|
||||
end
|
||||
|
||||
it('supports timeout = 0', function()
|
||||
local ret = exec_lua [[
|
||||
return vim.system({ 'sleep', '1' }):wait(0)
|
||||
]] --[[ @as any ]]
|
||||
eq({
|
||||
code = 124,
|
||||
signal = 15, -- SIGTERM
|
||||
stdout = '',
|
||||
stderr = '',
|
||||
}, ret)
|
||||
end)
|
||||
|
||||
it('kill processes', function()
|
||||
exec_lua([[
|
||||
local signal
|
||||
|
|
Loading…
Reference in New Issue