You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go.nvim/lua/go/health.lua

184 lines
4.3 KiB
Lua

2 years ago
local M = {}
1 year ago
local util = require('go.utils')
2 years ago
local log = util.log
local sep = util.sep()
local health = vim.health
if not vim.health then
1 year ago
health = require('health')
end
1 year ago
local tools = require('go.install').tools
2 years ago
local nvim_09 = vim.fn.has('nvim-0.9') == 1
local start = nvim_09 and health.start or health.report_start
local ok = nvim_09 and health.ok or health.report_ok
local error = nvim_09 and health.error or health.report_error
local warn = nvim_09 and health.warn or health.report_warn
local info = nvim_09 and health.info or health.report_info
local vfn = vim.fn
2 years ago
local function binary_check()
start('Binaries')
2 years ago
local no_err = true
1 year ago
local go_bin = 'go'
if vfn.executable(go_bin) == 1 then
1 year ago
info(go_bin .. ' installed.')
2 years ago
else
1 year ago
error(go_bin .. ' is not installed.')
2 years ago
no_err = false
end
for _, val in ipairs(tools) do
log(val)
if vfn.executable(val) == 1 then
1 year ago
info('Tool installed: ' .. val)
2 years ago
else
1 year ago
warn('Missing tool: ' .. val)
no_err = false
2 years ago
end
end
if vfn.executable('sed') == 1 then
1 year ago
info('sed installed.')
else
no_err = false
1 year ago
warn('sed is not installed. gotests may not fully work')
end
if vfn.executable('curl') == 1 then
1 year ago
info('curl installed.')
else
no_err = false
1 year ago
warn('curl is not installed, gocheat will not work.')
end
local parser_path = vim.api.nvim_get_runtime_file('parser' .. sep .. 'go.so', false)[1]
if not parser_path then
warn('go treesitter parser not found, please Run `:TSInstallSync go`')
no_err = false
end
if no_err then
1 year ago
ok('All binaries installed')
else
warn(
'Some binaries are not installed, please check if your $HOME/go/bin or $GOBIN $exists and in your $PATH'
)
end
2 years ago
end
local function plugin_check()
1 year ago
start('Go Plugin Check')
2 years ago
local plugins = {
1 year ago
'lspconfig',
'nvim-treesitter',
'guihua',
'nvim-dap-virtual-text',
'telescope',
2 years ago
}
local any_warn = false
local ts_installed = false
2 years ago
for _, plugin in ipairs(plugins) do
local pi = util.load_plugin(plugin)
if pi ~= nil then
1 year ago
ok(string.format('%s: plugin is installed', plugin))
if plugin == 'nvim-treesitter' then
ts_installed = true
end
2 years ago
else
any_warn = true
1 year ago
warn(string.format('%s: not installed/loaded', plugin))
2 years ago
end
end
if ts_installed then
1 year ago
local _info = require('nvim-treesitter.info').installed_parsers()
if vim.tbl_contains(_info, 'go') then
ok('nvim-treesitter-go is installed')
else
warn('nvim-treesitter-go is not installed, Please run TSInstall go to install')
any_warn = true
end
end
2 years ago
plugins = {
1 year ago
['nvim-dap'] = 'dap',
['nvim-dap-ui'] = 'dapui',
2 years ago
}
for name, req in pairs(plugins) do
local pi = util.load_plugin(name, req)
if pi ~= nil then
1 year ago
ok(string.format('%s: plugin is installed', name))
2 years ago
else
any_warn = true
1 year ago
warn(string.format('%s: not installed/loaded', name))
2 years ago
end
end
if any_warn then
1 year ago
warn('Not all plugin installed')
2 years ago
else
1 year ago
ok('All plugin installed')
2 years ago
end
end
-- check if GOBIN is in PATH
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 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 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
1 year ago
local function env_check()
local env = goenv()
local keys = { 'GOROOT', 'GOBIN' }
local any_warn = false
for _, key in ipairs(keys) do
if env[key] == nil then
info(string.format('%s is not set', key))
any_warn = true
else
ok(string.format('%s is set', key))
end
end
if any_warn then
info('Not all environment variables set')
else
ok('All environment variables set')
end
if not path_check(env['GOBIN']) then
warn('GOBIN is not in PATH')
else
ok('GOBIN is in PATH')
end
end
2 years ago
function M.check()
if vim.fn.has('nvim-0.9') == 0 then
warn('Suggested neovim version 0.9 or higher')
end
2 years ago
binary_check()
plugin_check()
env_check()
2 years ago
end
return M