might releated to issue #382 but it is different approch

pull/399/head
ray-x 7 months ago
parent 15bf9aea88
commit e749ff85ff

@ -122,8 +122,25 @@ local function plugin_check()
end
end
-- check if GOBIN is in PATH
local function path_check()
local gobin = vim.fn.systemlist('go env 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'
-- check GOBIN inside PATH
if not vim.tbl_contains(vim.split(path, ':', { trimempty = true }), gobin) then
return false
end
return true
end
local function env_check()
local envs = { 'GOPATH', 'GOROOT', 'GOBIN' }
local envs = { 'GOROOT', 'GOBIN' }
local any_warn = false
for _, env in ipairs(envs) do
if vim.env[env] == nil then
@ -138,6 +155,11 @@ local function env_check()
else
ok('All environment variables set')
end
if not path_check() then
warn('GOBIN is not in PATH')
else
ok('GOBIN is in PATH')
end
end
function M.check()

@ -62,7 +62,7 @@ local function is_installed(bin)
end
local env_path = os.getenv('PATH')
local base_paths = vim.split(env_path, sep, true)
local base_paths = vim.split(env_path, sep, { trimempty = true })
for _, value in pairs(base_paths) do
if uv.fs_stat(value .. DIR_SEP .. bin .. ext) then
@ -92,7 +92,10 @@ local function go_install_sync(pkg)
if vim.v.shell_error ~= 0 then
vim.notify('install ' .. pkg .. ' failed: ' .. output, vim.log.levels.ERROR)
else
vim.notify('install ' .. pkg .. ' success', vim.log.levels.INFO)
vim.notify(
'install ' .. pkg .. ' installed to ' .. (vim.env['GOBIN'] or vim.fn.system('go env GOBIN')),
vim.log.levels.INFO
)
end
end

Loading…
Cancel
Save