diff options
| author | William Boman <william@redwill.se> | 2025-07-25 09:54:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-25 09:54:47 +0200 |
| commit | edd8f7bce8f86465349b24e235718eb3ea52878d (patch) | |
| tree | 71ed79f104c3f89a222c5d2068d049e68353fd4b /lua/mason-core | |
| parent | fix(fetch): add busybox wget support (#1829) (diff) | |
| download | mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar.gz mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar.bz2 mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar.lz mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar.xz mason-edd8f7bce8f86465349b24e235718eb3ea52878d.tar.zst mason-edd8f7bce8f86465349b24e235718eb3ea52878d.zip | |
fix(spawn): fix locating exepath on Windows systems using a Unix `'shell'` (#1991)
Fixes #1961.
Diffstat (limited to 'lua/mason-core')
| -rw-r--r-- | lua/mason-core/spawn.lua | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lua/mason-core/spawn.lua b/lua/mason-core/spawn.lua index 038d7853..d604dfe2 100644 --- a/lua/mason-core/spawn.lua +++ b/lua/mason-core/spawn.lua @@ -13,6 +13,21 @@ local spawn = { _flatten_cmd_args = _.compose(_.filter(is_not_nil), _.flatten), } +---@param cmd string +local function exepath(cmd) + if platform.is.win then + -- On Windows, exepath() assumes the system is capable of executing "Unix-like" executables if the shell is a Unix + -- shell. We temporarily override it to a Windows shell ("powershell") to avoid that behaviour. + local old_shell = vim.o.shell + vim.o.shell = "powershell" + local expanded_cmd = vim.fn.exepath(cmd) + vim.o.shell = old_shell + return expanded_cmd + else + return vim.fn.exepath(cmd) + end +end + local function Failure(err, cmd) return Result.failure(setmetatable(err, { __tostring = function() @@ -67,7 +82,7 @@ setmetatable(spawn, { -- in PATH. if platform.is.win and (spawn_args.env and has_path(spawn_args.env)) == nil then a.scheduler() - local expanded_cmd = vim.fn.exepath(canonical_cmd) + local expanded_cmd = exepath(canonical_cmd) if expanded_cmd ~= "" then cmd = expanded_cmd end |
