aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_defaults.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-04-15 04:33:09 -0700
committerGitHub <noreply@github.com>2024-04-15 04:33:09 -0700
commit57adf8c6e01d9395eb52fe03571c535571efdc4b (patch)
treef5f999287509f2970c4f9034934fbecdfadb83ca /runtime/lua/vim/_defaults.lua
parent4ec8fd43bfdf1924ee03e07afc8a46dfdd3c9b12 (diff)
downloadrneovim-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/_defaults.lua')
-rw-r--r--runtime/lua/vim/_defaults.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 533ebbc7c3..5ada64a358 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -95,10 +95,19 @@ do
{ silent = true, expr = true, desc = ':help v_@-default' }
)
- --- Map |gx| to call |vim.ui.open| on the identifier under the cursor
+ --- Map |gx| to call |vim.ui.open| on the <cfile> at cursor.
do
local function do_open(uri)
- local _, err = vim.ui.open(uri)
+ local cmd, err = vim.ui.open(uri)
+ local rv = cmd and cmd:wait(1000) or nil
+ if cmd and rv and rv.code ~= 0 then
+ err = ('vim.ui.open: command %s (%d): %s'):format(
+ (rv.code == 124 and 'timeout' or 'failed'),
+ rv.code,
+ vim.inspect(cmd.cmd)
+ )
+ end
+
if err then
vim.notify(err, vim.log.levels.ERROR)
end