fix(vim.ui): open() may wait indefinitely #28325

Problem:
vim.ui.open "locks up" Nvim if the spawned process does not terminate. #27986

Solution:
- Change `vim.ui.open()`:
    - Do not call `wait()`.
    - Return a `SystemObj`. The caller can decide if it wants to `wait()`.
- Change `gx` to `wait()` only a short time.
    - Allows `gx` to show a message if the command fails, without the
      risk of waiting forever.
This commit is contained in:
Justin M. Keyes
2024-04-15 04:33:09 -07:00
committed by GitHub
parent 4ec8fd43bf
commit 57adf8c6e0
7 changed files with 38 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
local t = require('test.functional.testutil')()
local eq = t.eq
local matches = t.matches
local ok = t.ok
local exec_lua = t.exec_lua
local clear = t.clear
local feed = t.feed
@@ -138,13 +138,12 @@ describe('vim.ui', function()
describe('open()', function()
it('validation', function()
if is_os('win') or not is_ci('github') then
exec_lua [[vim.system = function() return { wait=function() return { code=3} end } end]]
exec_lua [[vim.system = function() return { wait=function() return { code=3 } end } end]]
end
if not is_os('bsd') then
matches(
'vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }',
exec_lua [[local _, err = vim.ui.open('non-existent-file') ; return err]]
)
local rv =
exec_lua [[local cmd = vim.ui.open('non-existent-file'); return cmd:wait(100).code]]
ok(type(rv) == 'number' and rv ~= 0, 'nonzero exit code', rv)
end
exec_lua [[