From 519b9929e94c94965b73ac4b04aedb03fd2708ca Mon Sep 17 00:00:00 2001 From: marshmallow Date: Wed, 19 Jul 2023 10:06:20 +1000 Subject: [PATCH 1/2] fix(ui.open): some URLs fail on Windows Problem: On Windows, `explorer.exe` fails to open some URLs, for example: :lua vim.ui.open('https://devdocs.io/#q=lua%20lua_call') https://github.com/neovim/neovim/pull/23401#issuecomment-1641015704 Solution: Use rundll32 instead. --- runtime/lua/vim/ui.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index fd06611da2..87b52787a0 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -136,7 +136,11 @@ function M.open(path) if vim.fn.has('mac') == 1 then cmd = { 'open', path } elseif vim.fn.has('win32') == 1 then - cmd = { 'explorer', path } + if vim.fn.executable('rundll32') == 1 then + cmd = { 'rundll32', 'url.dll,FileProtocolHandler', path } + else + return nil, 'vim.ui.open: rundll32 not found' + end elseif vim.fn.executable('wslview') == 1 then cmd = { 'wslview', path } elseif vim.fn.executable('xdg-open') == 1 then From 7907b1fca5fce69e966ab1071df8e6d11afda41d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 21 Jul 2023 13:34:38 +0200 Subject: [PATCH 2/2] test(vim.ui.open): mock failure on Windows Problem: On Windows, `rundll32` exits zero (success) even when given a non-existent file. Solution: Mock vim.system() on Windows to force a "failure" case. --- test/functional/lua/ui_spec.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 808b25d9ea..d4c150c5f2 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -6,6 +6,7 @@ local clear = helpers.clear local feed = helpers.feed local eval = helpers.eval local is_ci = helpers.is_ci +local is_os = helpers.is_os local poke_eventloop = helpers.poke_eventloop describe('vim.ui', function() @@ -134,8 +135,11 @@ describe('vim.ui', function() describe('open()', function() it('validation', function() - if is_ci('github') then - matches('vim.ui.open: command failed %(%d%): { "[^"]+", "non%-existent%-file" }', + if is_os('win') or not is_ci('github') then + exec_lua[[vim.system = function() return { wait=function() return { code=3} end } end]] + end + if not is_os('bsd') then + matches('vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }', exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]]) end