From e0d92b9cc20b58179599f53dfa74ca821935a539 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 25 Apr 2024 04:15:58 -0700 Subject: fix(vim.ui)!: change open() to return pcall-like values #28502 Problem: `vim.ui.open` unnecessarily invents a different success/failure convention. Its return type was changed in 57adf8c6e01d, so we might as well change it to have a more conventional form. Solution: Change the signature to use the `pcall` convention of `status, result`. --- runtime/lua/vim/_defaults.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 68ad95b725..419a29a5c6 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -98,18 +98,19 @@ do --- Map |gx| to call |vim.ui.open| on the at cursor. do local function do_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( + local ok, cmd_or_err = vim.ui.open(uri) + local rv = ok and (cmd_or_err --[[@as vim.SystemObj]]):wait(1000) or nil + if rv and rv.code ~= 0 then + ok = false + cmd_or_err = ('vim.ui.open: command %s (%d): %s'):format( (rv.code == 124 and 'timeout' or 'failed'), rv.code, - vim.inspect(cmd.cmd) + vim.inspect(cmd_or_err.cmd) ) end - if err then - vim.notify(err, vim.log.levels.ERROR) + if not ok then + vim.notify(cmd_or_err --[[@as string]], vim.log.levels.ERROR) end end -- cgit