Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix run in external terminal not propagating environment variables to program #1318

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ local function coresume(co)
end


local function launch_external_terminal(terminal, args)
local function launch_external_terminal(env, terminal, args)
local handle
local pid_or_err
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)
end
end
local opts = {
args = full_args,
detached = true
detached = true,
env = env_formatted,
}
handle, pid_or_err = uv.spawn(terminal.command, opts, function(code)
if handle then
Expand Down Expand Up @@ -202,7 +210,7 @@ local function run_in_terminal(lsession, request)
if not terminal then
utils.notify('Requested external terminal, but none configured. Fallback to integratedTerminal', vim.log.levels.WARN)
else
local handle, pid = launch_external_terminal(terminal, body.args)
local handle, pid = launch_external_terminal(body.env, terminal, body.args)
if not handle then
utils.notify('Could not launch terminal ' .. terminal.command, vim.log.levels.ERROR)
end
Expand Down
Loading