From fd085d90820149caecf213b299f19e46305043ee Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 20 Apr 2024 05:47:08 -0700 Subject: [PATCH] fix(vim.ui.open): try wslview before explorer.exe #28424 Problem: explorer.exe is unreliable on WSL. Solution: Try wslview before explorer.exe. fix #28410 --- runtime/lua/vim/ui.lua | 4 +++- test/functional/lua/ui_spec.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index b6695734a3..e02acaf25c 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -149,12 +149,14 @@ function M.open(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('explorer.exe') == 1 then cmd = { 'explorer.exe', path } elseif vim.fn.executable('xdg-open') == 1 then cmd = { 'xdg-open', path } else - return nil, 'vim.ui.open: no handler found (tried: explorer.exe, xdg-open)' + return nil, 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open)' end return vim.system(cmd, { text = true, detach = true }), nil diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index 71a04a9ae6..2472725c56 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -151,7 +151,7 @@ describe('vim.ui', function() vim.fn.executable = function() return 0 end ]] eq( - 'vim.ui.open: no handler found (tried: explorer.exe, xdg-open)', + 'vim.ui.open: no handler found (tried: wslview, explorer.exe, xdg-open)', exec_lua [[local _, err = vim.ui.open('foo') ; return err]] ) end)