aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/rpc.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2020-02-09 00:05:48 -0800
committerJustin M. Keyes <justinkz@gmail.com>2020-02-16 22:09:28 -0800
commita446fbc8fa278d9c1e4144dc9767c9dc0b184583 (patch)
tree5f3f09587306f2caf50effab0aa001716ea8a2bb /runtime/lua/vim/lsp/rpc.lua
parent4cf48dc329e3e3f451ecf902af9af6317d44bb40 (diff)
downloadrneovim-a446fbc8fa278d9c1e4144dc9767c9dc0b184583.tar.gz
rneovim-a446fbc8fa278d9c1e4144dc9767c9dc0b184583.tar.bz2
rneovim-a446fbc8fa278d9c1e4144dc9767c9dc0b184583.zip
lsp/rpc.lua: fix `env` application function
Env vars must be merged with the current env.
Diffstat (limited to 'runtime/lua/vim/lsp/rpc.lua')
-rw-r--r--runtime/lua/vim/lsp/rpc.lua51
1 files changed, 19 insertions, 32 deletions
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index e13b05610b..74d73da31f 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -33,38 +33,25 @@ local function convert_NIL(v)
return v
end
--- If a dictionary is passed in, turn it into a list of string of "k=v"
--- Accepts a table which can be composed of k=v strings or map-like
--- specification, such as:
---
--- ```
--- {
--- "PRODUCTION=false";
--- "PATH=/usr/bin/";
--- PORT = 123;
--- HOST = "0.0.0.0";
--- }
--- ```
---
--- 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
+--- Merges current process env with the given env and returns the result as
+--- a list of "k=v" strings.
+---
+--- Example:
+---
+--- { PRODUCTION="false", PATH="/usr/bin/", PORT=123, HOST="0.0.0.0", }
+--- => { "PRODUCTION=false", "PATH=/usr/bin/", "PORT=123", "HOST=0.0.0.0", }
+local function env_merge(env)
+ if env == nil then
+ return env
+ 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
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
assert(is_dir(spawn_params.cwd), "cwd must be a directory")
end
- spawn_params.env = force_env_list(extra_spawn_params.env)
+ spawn_params.env = env_merge(extra_spawn_params.env)
end
handle, pid = uv.spawn(cmd, spawn_params, onexit)
end