@ -124,14 +124,13 @@ end
-- check if GOBIN is in PATH
local function path_check ( )
local gobin = vim.fn . systemlist ( ' go env GOBIN ' )
local function path_check ( gobin )
local path = os.getenv ( ' PATH ' )
if gobin == ' ' or vim.v . shell_error ~= 0 then
util.error ( ' GOBIN is not set ' )
return false
end
gobin = gobin [ 1 ] or ' notfound '
gobin = gobin or ' notfound '
-- check GOBIN inside PATH
if not vim.tbl_contains ( vim.split ( path , ' : ' , { trimempty = true } ) , gobin ) then
return false
@ -139,15 +138,25 @@ local function path_check()
return true
end
local function goenv ( )
local env = { }
local raw = vim.fn . system ( ' go env ' )
for key , value in string.gmatch ( raw , " ([^=]+)='([^']*)' \n " ) do
env [ key ] = # value > 0 and value or nil
end
return env
end
local function env_check ( )
local envs = { ' GOROOT ' , ' GOBIN ' }
local env = goenv ( )
local keys = { ' GOROOT ' , ' GOBIN ' }
local any_warn = false
for _ , env in ipairs ( envs ) do
if vim.env [ env ] == nil then
info ( string.format ( ' %s is not set ' , env ) )
for _ , key in ipairs ( key s) do
if env[ key ] == nil then
info ( string.format ( ' %s is not set ' , key ) )
any_warn = true
else
ok ( string.format ( ' %s is set ' , env ) )
ok ( string.format ( ' %s is set ' , key ) )
end
end
if any_warn then
@ -155,7 +164,7 @@ local function env_check()
else
ok ( ' All environment variables set ' )
end
if not path_check ( ) then
if not path_check ( env [ " GOBIN " ] ) then
warn ( ' GOBIN is not in PATH ' )
else
ok ( ' GOBIN is in PATH ' )