mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
lsp/rpc.lua: fix env
application function
Env vars must be merged with the current env.
This commit is contained in:
@@ -33,38 +33,25 @@ local function convert_NIL(v)
|
|||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If a dictionary is passed in, turn it into a list of string of "k=v"
|
--- Merges current process env with the given env and returns the result as
|
||||||
-- Accepts a table which can be composed of k=v strings or map-like
|
--- a list of "k=v" strings.
|
||||||
-- specification, such as:
|
---
|
||||||
--
|
--- Example:
|
||||||
-- ```
|
---
|
||||||
-- {
|
--- { PRODUCTION="false", PATH="/usr/bin/", PORT=123, HOST="0.0.0.0", }
|
||||||
-- "PRODUCTION=false";
|
--- => { "PRODUCTION=false", "PATH=/usr/bin/", "PORT=123", "HOST=0.0.0.0", }
|
||||||
-- "PATH=/usr/bin/";
|
local function env_merge(env)
|
||||||
-- PORT = 123;
|
if env == nil then
|
||||||
-- HOST = "0.0.0.0";
|
return env
|
||||||
-- }
|
|
||||||
-- ```
|
|
||||||
--
|
|
||||||
-- Non-string values will be cast with `tostring`
|
|
||||||
local function force_env_list(final_env)
|
|
||||||
if final_env then
|
|
||||||
local env = final_env
|
|
||||||
final_env = {}
|
|
||||||
for k,v in pairs(env) do
|
|
||||||
-- If it's passed in as a dict, then convert to list of "k=v"
|
|
||||||
if type(k) == "string" then
|
|
||||||
table.insert(final_env, k..'='..tostring(v))
|
|
||||||
elseif type(v) == 'string' then
|
|
||||||
table.insert(final_env, v)
|
|
||||||
else
|
|
||||||
-- TODO is this right or should I exception here?
|
|
||||||
-- Try to coerce other values to string.
|
|
||||||
table.insert(final_env, tostring(v))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return final_env
|
|
||||||
end
|
end
|
||||||
|
-- Merge.
|
||||||
|
env = vim.tbl_extend('force', vim.fn.environ(), env)
|
||||||
|
local final_env = {}
|
||||||
|
for k,v in pairs(env) do
|
||||||
|
assert(type(k) == 'string', 'env must be a dict')
|
||||||
|
table.insert(final_env, k..'='..tostring(v))
|
||||||
|
end
|
||||||
|
return final_env
|
||||||
end
|
end
|
||||||
|
|
||||||
local function format_message_with_content_length(encoded_message)
|
local function format_message_with_content_length(encoded_message)
|
||||||
@@ -262,7 +249,7 @@ local function create_and_start_client(cmd, cmd_args, handlers, extra_spawn_para
|
|||||||
if spawn_params.cwd then
|
if spawn_params.cwd then
|
||||||
assert(is_dir(spawn_params.cwd), "cwd must be a directory")
|
assert(is_dir(spawn_params.cwd), "cwd must be a directory")
|
||||||
end
|
end
|
||||||
spawn_params.env = force_env_list(extra_spawn_params.env)
|
spawn_params.env = env_merge(extra_spawn_params.env)
|
||||||
end
|
end
|
||||||
handle, pid = uv.spawn(cmd, spawn_params, onexit)
|
handle, pid = uv.spawn(cmd, spawn_params, onexit)
|
||||||
end
|
end
|
||||||
|
@@ -369,7 +369,7 @@ function tests.basic_check_buffer_open_and_change_incremental()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function tests.basic_check_buffer_open_and_change_incremental_editting()
|
function tests.basic_check_buffer_open_and_change_incremental_editing()
|
||||||
skeleton {
|
skeleton {
|
||||||
on_init = function(params)
|
on_init = function(params)
|
||||||
local expected_capabilities = protocol.make_client_capabilities()
|
local expected_capabilities = protocol.make_client_capabilities()
|
||||||
@@ -422,6 +422,7 @@ local kill_timer = vim.loop.new_timer()
|
|||||||
kill_timer:start(_G.TIMEOUT or 1e3, 0, function()
|
kill_timer:start(_G.TIMEOUT or 1e3, 0, function()
|
||||||
kill_timer:stop()
|
kill_timer:stop()
|
||||||
kill_timer:close()
|
kill_timer:close()
|
||||||
|
-- TODO: log('TIMEOUT')
|
||||||
io.stderr:write("TIMEOUT")
|
io.stderr:write("TIMEOUT")
|
||||||
os.exit(100)
|
os.exit(100)
|
||||||
end)
|
end)
|
||||||
@@ -432,6 +433,7 @@ local status, err = pcall(assert(tests[test_name], "Test not found"))
|
|||||||
kill_timer:stop()
|
kill_timer:stop()
|
||||||
kill_timer:close()
|
kill_timer:close()
|
||||||
if not status then
|
if not status then
|
||||||
|
-- TODO: log(err)
|
||||||
io.stderr:write(err)
|
io.stderr:write(err)
|
||||||
os.exit(101)
|
os.exit(101)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user