aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-11-07 16:21:49 +0000
committerLewis Russell <me@lewisr.dev>2024-11-08 16:29:44 +0000
commitad3472e291694b6c589d8a664459b03962eaac95 (patch)
tree197a9c110fa4d506a77cb8f2a8f53185f3f40515
parent7342e6b00d5e9f67fd5ad4d3fadaf7e501598486 (diff)
downloadrneovim-ad3472e291694b6c589d8a664459b03962eaac95.tar.gz
rneovim-ad3472e291694b6c589d8a664459b03962eaac95.tar.bz2
rneovim-ad3472e291694b6c589d8a664459b03962eaac95.zip
fix(vim.system): resolve executable paths on windows
Fixes #31107
-rw-r--r--runtime/lua/vim/_system.lua9
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--test/functional/lua/system_spec.lua12
3 files changed, 20 insertions, 2 deletions
diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua
index 9e27b4c152..ce5dbffeaa 100644
--- a/runtime/lua/vim/_system.lua
+++ b/runtime/lua/vim/_system.lua
@@ -230,6 +230,8 @@ local function default_handler(stream, text, bucket)
end
end
+local is_win = vim.fn.has('win32') == 1
+
local M = {}
--- @param cmd string
@@ -238,6 +240,13 @@ local M = {}
--- @param on_error fun()
--- @return uv.uv_process_t, integer
local function spawn(cmd, opts, on_exit, on_error)
+ if is_win then
+ local cmd1 = vim.fn.exepath(cmd)
+ if cmd1 ~= '' then
+ cmd = cmd1
+ end
+ end
+
local handle, pid_or_err = uv.spawn(cmd, opts, on_exit)
if not handle then
on_error()
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 870eb17b9e..601c07cfab 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -2165,6 +2165,7 @@ M.funcs = {
If {expr} starts with "./" the |current-directory| is used.
]=],
+ fast = true,
name = 'exepath',
params = { { 'expr', 'string' } },
signature = 'exepath({expr})',
diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua
index 482bfcf1a9..afbada007d 100644
--- a/test/functional/lua/system_spec.lua
+++ b/test/functional/lua/system_spec.lua
@@ -9,7 +9,7 @@ local function system_sync(cmd, opts)
return exec_lua(function()
local obj = vim.system(cmd, opts)
- if opts.timeout then
+ if opts and opts.timeout then
-- Minor delay before calling wait() so the timeout uv timer can have a headstart over the
-- internal call to vim.wait() in wait().
vim.wait(10)
@@ -75,7 +75,7 @@ describe('vim.system', function()
it('kill processes', function()
exec_lua(function()
- local signal
+ local signal --- @type integer?
local cmd = vim.system({ 'cat', '-' }, { stdin = true }, function(r)
signal = r.signal
end) -- run forever
@@ -112,4 +112,12 @@ describe('vim.system', function()
)
eq(true, exec_lua([[return _G.processed]]))
end)
+
+ if t.is_os('win') then
+ it('can resolve windows command extentions.', function()
+ t.write_file('test.bat', 'echo hello world')
+ system_sync({ 'chmod', '+x', 'test.bat' })
+ system_sync({ './test' })
+ end)
+ end
end)