Skip to content

Commit

Permalink
Always inherit environment when launching external terminal (#1340)
Browse files Browse the repository at this point in the history
Follow up to #1318

The intention of that change was to honor environment variables sent by the
debug adapter, but it also unintentionally changed behavior to no longer
inherit the parent environment if no `env` option was provided by the debug
adapter.

This fixes it, so that:

- No `env` provided: Use parent environment
- `env` provided: Merge with parent environment. (`env` having higher priority)
  • Loading branch information
apognu authored Sep 28, 2024
1 parent 90616ae commit 7ff6936
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,15 @@ local function launch_external_terminal(env, terminal, args)
local full_args = {}
vim.list_extend(full_args, terminal.args or {})
vim.list_extend(full_args, args)
local env_formatted = {}
-- Copy environment, prefer vars set by client
for k, v in pairs(env and vim.tbl_extend('keep', env, vim.fn.environ()) or {}) do
if k:find "^[^=]*$" then -- correct variable?
env_formatted[#env_formatted+1] = k.."="..tostring(v)
-- Initializing to nil is important so environment is inherited by the terminal
local env_formatted = nil
if env then
env_formatted = {}
-- Copy environment, prefer vars set by client
for k, v in pairs(vim.tbl_extend('keep', env, vim.fn.environ())) do
if k:find "^[^=]*$" then -- correct variable?
env_formatted[#env_formatted+1] = k.."="..tostring(v)
end
end
end
local opts = {
Expand Down

0 comments on commit 7ff6936

Please sign in to comment.