Skip to content

Commit edd8f7b

Browse files
authored
fix(spawn): fix locating exepath on Windows systems using a Unix 'shell' (#1991)
Fixes #1961.
1 parent 8024d64 commit edd8f7b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lua/mason-core/spawn.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ local spawn = {
1313
_flatten_cmd_args = _.compose(_.filter(is_not_nil), _.flatten),
1414
}
1515

16+
---@param cmd string
17+
local function exepath(cmd)
18+
if platform.is.win then
19+
-- On Windows, exepath() assumes the system is capable of executing "Unix-like" executables if the shell is a Unix
20+
-- shell. We temporarily override it to a Windows shell ("powershell") to avoid that behaviour.
21+
local old_shell = vim.o.shell
22+
vim.o.shell = "powershell"
23+
local expanded_cmd = vim.fn.exepath(cmd)
24+
vim.o.shell = old_shell
25+
return expanded_cmd
26+
else
27+
return vim.fn.exepath(cmd)
28+
end
29+
end
30+
1631
local function Failure(err, cmd)
1732
return Result.failure(setmetatable(err, {
1833
__tostring = function()
@@ -67,7 +82,7 @@ setmetatable(spawn, {
6782
-- in PATH.
6883
if platform.is.win and (spawn_args.env and has_path(spawn_args.env)) == nil then
6984
a.scheduler()
70-
local expanded_cmd = vim.fn.exepath(canonical_cmd)
85+
local expanded_cmd = exepath(canonical_cmd)
7186
if expanded_cmd ~= "" then
7287
cmd = expanded_cmd
7388
end

0 commit comments

Comments
 (0)