From 4eebc46930008d7cf47491121556ee201e1f4860 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 2 Jul 2025 12:08:48 +0100 Subject: fix(vim.system): env=nil passes env=nil to uv.spawn 731e616a79 made it so passing `{env = nil, clear_env = true }` would pass `{env = {}}` to `vim.uv.spawn`. However this is not what `clear_env` is (arguably) supposed to do. If `env=nil` then that implies the uses wants `vim.uv.spawn()` to use the default environment. Adding `clear_env = true` simply prevents `NVIM` (the base environment) from being added. Fixes #34730 --- runtime/lua/vim/_editor.lua | 2 +- runtime/lua/vim/_system.lua | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 165fdf373f..ffec37bb11 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -106,7 +106,7 @@ local utfs = { --- - env: table Set environment variables for the new process. Inherits the --- current environment with `NVIM` set to |v:servername|. --- - clear_env: (boolean) `env` defines the job environment exactly, instead of merging current ---- environment. +--- environment. Note: if `env` is `nil`, the current environment is used but without `NVIM` set. --- - stdin: (string|string[]|boolean) If `true`, then a pipe to stdin is opened and can be written --- to via the `write()` method to SystemObj. If string or string[] then will be written to stdin --- and closed. Defaults to `false`. diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua index 38e348bc03..ced341fe28 100644 --- a/runtime/lua/vim/_system.lua +++ b/runtime/lua/vim/_system.lua @@ -208,13 +208,18 @@ end --- @param clear_env? boolean --- @return string[]? local function setup_env(env, clear_env) + if not env and clear_env then + return + end + + env = env or {} if not clear_env then --- @type table - env = vim.tbl_extend('force', base_env(), env or {}) + env = vim.tbl_extend('force', base_env(), env) end local renv = {} --- @type string[] - for k, v in pairs(env or {}) do + for k, v in pairs(env) do renv[#renv + 1] = string.format('%s=%s', k, tostring(v)) end -- cgit