diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-04-25 04:15:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 04:15:58 -0700 |
commit | e0d92b9cc20b58179599f53dfa74ca821935a539 (patch) | |
tree | 29c8f5c83f2c2935c87036f7a57ff806354b4ec4 /runtime/lua/vim/ui.lua | |
parent | a1c2da56ecef9c7a0e17be02f587d7c7f9eee170 (diff) | |
download | rneovim-e0d92b9cc20b58179599f53dfa74ca821935a539.tar.gz rneovim-e0d92b9cc20b58179599f53dfa74ca821935a539.tar.bz2 rneovim-e0d92b9cc20b58179599f53dfa74ca821935a539.zip |
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`.
Diffstat (limited to 'runtime/lua/vim/ui.lua')
-rw-r--r-- | runtime/lua/vim/ui.lua | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index e02acaf25c..b8323efa66 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -118,16 +118,16 @@ end --- vim.ui.open("https://neovim.io/") --- vim.ui.open("~/path/to/file") --- -- Synchronous (wait until the process exits). ---- local cmd, err = vim.ui.open("$VIMRUNTIME") ---- if cmd then +--- local ok, cmd = vim.ui.open("$VIMRUNTIME") +--- if ok then --- cmd:wait() --- end --- ``` --- ---@param path string Path or URL to open --- ----@return vim.SystemObj|nil # Command object, or nil if not found. ----@return string|nil # Error message on failure +---@return boolean # false if command not found, else true. +---@return vim.SystemObj|string # Command object, or error message on failure --- ---@see |vim.system()| function M.open(path) @@ -147,7 +147,7 @@ function M.open(path) if vim.fn.executable('rundll32') == 1 then cmd = { 'rundll32', 'url.dll,FileProtocolHandler', path } else - return nil, 'vim.ui.open: rundll32 not found' + return false, 'vim.ui.open: rundll32 not found' end elseif vim.fn.executable('wslview') == 1 then cmd = { 'wslview', path } @@ -156,10 +156,10 @@ function M.open(path) elseif vim.fn.executable('xdg-open') == 1 then cmd = { 'xdg-open', path } else - return nil, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open)' + return false, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open)' end - return vim.system(cmd, { text = true, detach = true }), nil + return true, vim.system(cmd, { text = true, detach = true }) end return M |