aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/ui.lua
diff options
context:
space:
mode:
authorskewb1k <skewb1kunix@gmail.com>2026-01-27 16:51:00 +0300
committerGitHub <noreply@github.com>2026-01-27 08:51:00 -0500
commit8c63d84be157a0a944ff9a3eb7d62c2ea2d50f94 (patch)
treeddb08c39d55d4c00c5a3ec232447aae603efc057 /runtime/lua/vim/ui.lua
parent76c77bd114ee5c3be0e448018c4f3a17cf8bcf42 (diff)
downloadrneovim-8c63d84be157a0a944ff9a3eb7d62c2ea2d50f94.tar.gz
rneovim-8c63d84be157a0a944ff9a3eb7d62c2ea2d50f94.tar.bz2
rneovim-8c63d84be157a0a944ff9a3eb7d62c2ea2d50f94.zip
feat(health): check `vim.ui.open()` tool #37569
Problem: `:checkhealth` does not report when no `vim.ui.open()` handler is available. Solution: Factor command resolution into `_get_open_cmd()` and reuse it from `:checkhealth` to detect missing handlers.
Diffstat (limited to 'runtime/lua/vim/ui.lua')
-rw-r--r--runtime/lua/vim/ui.lua39
1 files changed, 28 insertions, 11 deletions
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua
index abcf7f8ba0..5a2cb662ef 100644
--- a/runtime/lua/vim/ui.lua
+++ b/runtime/lua/vim/ui.lua
@@ -166,25 +166,42 @@ function M.open(path, opt)
if opt.cmd then
cmd = vim.list_extend(opt.cmd --[[@as string[] ]], { path })
- elseif vim.fn.has('mac') == 1 then
- cmd = { 'open', path }
+ else
+ local open_cmd, err = M._get_open_cmd()
+ if err then
+ return nil, err
+ end
+ ---@cast open_cmd string[]
+ if open_cmd[1] == 'xdg-open' then
+ job_opt.stdout = false
+ job_opt.stderr = false
+ end
+ cmd = vim.list_extend(open_cmd, { path })
+ end
+
+ return vim.system(cmd, job_opt), nil
+end
+
+--- Get an available command used to open the path or URL.
+---
+--- @return string[]|nil # Command, or nil if not found.
+--- @return nil|string # Error message on failure, or nil on success.
+function M._get_open_cmd()
+ if vim.fn.has('mac') == 1 then
+ return { 'open' }, nil
elseif vim.fn.has('win32') == 1 then
- cmd = { 'cmd.exe', '/c', 'start', '', path }
+ return { 'cmd.exe', '/c', 'start', '' }, nil
elseif vim.fn.executable('xdg-open') == 1 then
- cmd = { 'xdg-open', path }
- job_opt.stdout = false
- job_opt.stderr = false
+ return { 'xdg-open' }, nil
elseif vim.fn.executable('wslview') == 1 then
- cmd = { 'wslview', path }
+ return { 'wslview' }, nil
elseif vim.fn.executable('explorer.exe') == 1 then
- cmd = { 'explorer.exe', path }
+ return { 'explorer.exe' }, nil
elseif vim.fn.executable('lemonade') == 1 then
- cmd = { 'lemonade', 'open', path }
+ return { 'lemonade', 'open' }, nil
else
return nil, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open, lemonade)'
end
-
- return vim.system(cmd, job_opt), nil
end
--- Returns all URLs at cursor, if any.