diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-04-15 04:33:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 04:33:09 -0700 |
commit | 57adf8c6e01d9395eb52fe03571c535571efdc4b (patch) | |
tree | f5f999287509f2970c4f9034934fbecdfadb83ca /runtime/lua/vim/ui.lua | |
parent | 4ec8fd43bfdf1924ee03e07afc8a46dfdd3c9b12 (diff) | |
download | rneovim-57adf8c6e01d9395eb52fe03571c535571efdc4b.tar.gz rneovim-57adf8c6e01d9395eb52fe03571c535571efdc4b.tar.bz2 rneovim-57adf8c6e01d9395eb52fe03571c535571efdc4b.zip |
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.
Diffstat (limited to 'runtime/lua/vim/ui.lua')
-rw-r--r-- | runtime/lua/vim/ui.lua | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index b0e7ca1a35..b6695734a3 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -114,14 +114,19 @@ end --- Examples: --- --- ```lua +--- -- Asynchronous. --- vim.ui.open("https://neovim.io/") --- vim.ui.open("~/path/to/file") ---- vim.ui.open("$VIMRUNTIME") +--- -- Synchronous (wait until the process exits). +--- local cmd, err = vim.ui.open("$VIMRUNTIME") +--- if cmd then +--- cmd:wait() +--- end --- ``` --- ---@param path string Path or URL to open --- ----@return vim.SystemCompleted|nil # Command result, or nil if not found. +---@return vim.SystemObj|nil # Command object, or nil if not found. ---@return string|nil # Error message on failure --- ---@see |vim.system()| @@ -152,13 +157,7 @@ function M.open(path) return nil, 'vim.ui.open: no handler found (tried: explorer.exe, xdg-open)' end - local rv = vim.system(cmd, { text = true, detach = true }):wait() - if rv.code ~= 0 then - local msg = ('vim.ui.open: command failed (%d): %s'):format(rv.code, vim.inspect(cmd)) - return rv, msg - end - - return rv, nil + return vim.system(cmd, { text = true, detach = true }), nil end return M |