diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-09-03 10:17:24 +0100 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-09-05 10:18:26 +0100 |
commit | a44521f46e6f79171d034e5cce1a4dc266d23e49 (patch) | |
tree | 956c8ea05033cb52d2c94cc65d4b21a72e4a4781 | |
parent | 6abc608445745e7e8def2aabf57c7a0c26b8a485 (diff) | |
download | rneovim-a44521f46e6f79171d034e5cce1a4dc266d23e49.tar.gz rneovim-a44521f46e6f79171d034e5cce1a4dc266d23e49.tar.bz2 rneovim-a44521f46e6f79171d034e5cce1a4dc266d23e49.zip |
fix(vim.system): let on_exit handle cleanup after kill
Fixes #25000
-rw-r--r-- | runtime/lua/vim/_system.lua | 11 | ||||
-rw-r--r-- | test/functional/lua/system_spec.lua | 24 |
2 files changed, 29 insertions, 6 deletions
diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua index 6f5e95eb24..ba3fc34e78 100644 --- a/runtime/lua/vim/_system.lua +++ b/runtime/lua/vim/_system.lua @@ -18,6 +18,7 @@ local uv = vim.uv --- @field stderr? string --- @class SystemState +--- @field cmd string[] --- @field handle? uv.uv_process_t --- @field timer? uv.uv_timer_t --- @field pid? integer @@ -63,11 +64,9 @@ local function new_systemobj(state) }, { __index = SystemObj }) end ---- @param signal integer +--- @param signal integer|string function SystemObj:kill(signal) - local state = self._state - state.handle:kill(signal) - close_handles(state) + self._state.handle:kill(signal) end local MAX_TIMEOUT = 2 ^ 31 @@ -159,7 +158,7 @@ end --- @return table<string,string> local function base_env() - local env = vim.fn.environ() + local env = vim.fn.environ() --- @type table<string,string> env['NVIM'] = vim.v.servername env['NVIM_LISTEN_ADDRESS'] = nil return env @@ -212,7 +211,7 @@ end local M = {} --- @param cmd string ---- @param opts uv.aliases.spawn_options +--- @param opts uv.spawn.options --- @param on_exit fun(code: integer, signal: integer) --- @param on_error fun() --- @return uv.uv_process_t, integer diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua index 836d3a83b0..35b9d5cc37 100644 --- a/test/functional/lua/system_spec.lua +++ b/test/functional/lua/system_spec.lua @@ -54,4 +54,28 @@ describe('vim.system', function() end) end + it('kill processes', function() + exec_lua([[ + local signal + local cmd = vim.system({ 'cat', '-' }, { stdin = true }, function(r) + signal = r.signal + end) -- run forever + + cmd:kill('sigint') + + -- wait for the process not to exist + local done = vim.wait(2000, function() + return signal ~= nil + end) + + assert(done, 'process did not exit') + + -- Check the process is no longer running + vim.fn.systemlist({'ps', 'p', tostring(cmd.pid)}) + assert(vim.v.shell_error == 1, 'dwqdqd '..vim.v.shell_error) + + assert(signal == 2) + ]]) + end) + end) |