fix(environment): run synchronously in parsing from cmd (#2062)
This commit is contained in:
@@ -31,25 +31,22 @@ function M.parse(key_name, override)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(cmd) == "string" then cmd = vim.split(cmd, " ", { trimempty = true }) end
|
if type(cmd) == "table" then cmd = table.concat(cmd, " ") end
|
||||||
|
|
||||||
Utils.debug("running command:", cmd)
|
Utils.debug("running command:", cmd)
|
||||||
local exit_codes = { 0 }
|
local exit_codes = { 0 }
|
||||||
local ok, job_or_err = pcall(vim.system, cmd, { text = true }, function(result)
|
|
||||||
local code = result.code
|
|
||||||
local stderr = result.stderr or ""
|
|
||||||
local stdout = result.stdout and vim.split(result.stdout, "\n") or {}
|
|
||||||
if vim.tbl_contains(exit_codes, code) then
|
|
||||||
value = stdout[1]
|
|
||||||
M.cache[cache_key] = value
|
|
||||||
else
|
|
||||||
Utils.error("failed to get key: (error code" .. code .. ")\n" .. stderr, { once = true, title = "Avante" })
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
if not ok then
|
local result = Utils.shell_run(cmd)
|
||||||
Utils.error("failed to run command: " .. cmd .. "\n" .. job_or_err)
|
local code = result.code
|
||||||
return
|
local stdout = result.stdout and vim.split(result.stdout, "\n") or {}
|
||||||
|
|
||||||
|
if vim.tbl_contains(exit_codes, code) then
|
||||||
|
value = stdout[1]
|
||||||
|
else
|
||||||
|
Utils.error(
|
||||||
|
"failed to get key: (error code" .. code .. ")\n" .. result.stdout,
|
||||||
|
{ once = true, title = "Avante" }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
value = os.getenv(key_name)
|
value = os.getenv(key_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user