2021-03-10 12:15:06 +00:00
|
|
|
local uv = vim.loop
|
2021-07-14 15:35:38 +00:00
|
|
|
local DIR_SEP = package.config:sub(1, 1)
|
2021-12-06 10:32:23 +00:00
|
|
|
local log = require("go.utils").log
|
2021-07-04 02:01:28 +00:00
|
|
|
|
2021-03-10 12:15:06 +00:00
|
|
|
local url = {
|
2021-07-14 15:35:38 +00:00
|
|
|
gofumpt = "mvdan.cc/gofumpt",
|
|
|
|
golines = "github.com/segmentio/golines",
|
2021-12-10 00:43:59 +00:00
|
|
|
golangci_lint = "github.com/golangci/golangci-lint/cmd/golangci-lint",
|
2021-08-24 04:53:37 +00:00
|
|
|
goimports = "golang.org/x/tools/cmd/goimports",
|
|
|
|
gorename = "golang.org/x/tools/cmd/gorename",
|
2021-07-04 02:01:28 +00:00
|
|
|
gomodifytags = "github.com/fatih/gomodifytags",
|
2021-12-21 09:24:17 +00:00
|
|
|
gopls = "golang.org/x/tools/gopls",
|
2021-09-02 10:03:38 +00:00
|
|
|
gotests = "github.com/cweill/gotests",
|
2021-12-06 10:32:23 +00:00
|
|
|
iferr = "github.com/koron/iferr",
|
|
|
|
impl = "github.com/josharian/impl",
|
|
|
|
fillstruct = "github.com/davidrjenni/reftools/cmd/fillstruct",
|
|
|
|
fixplurals = "github.com/davidrjenni/reftools/cmd/fixplurals",
|
|
|
|
fillswitch = "github.com/davidrjenni/reftools/cmd/fillswitch",
|
|
|
|
dlv = "github.com/go-delve/delve/cmd/dlv",
|
|
|
|
ginkgo = "github.com/onsi/ginkgo/ginkgo",
|
|
|
|
richgo = "github.com/kyoh86/richgo",
|
2021-03-10 12:15:06 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 10:32:23 +00:00
|
|
|
local gotools = {}
|
|
|
|
for tool, _ in pairs(url) do
|
|
|
|
table.insert(gotools, tool)
|
|
|
|
end
|
2021-07-04 02:01:28 +00:00
|
|
|
local function is_installed(bin)
|
2021-07-14 15:35:38 +00:00
|
|
|
local env_path = os.getenv("PATH")
|
|
|
|
local base_paths = vim.split(env_path, ":", true)
|
2021-07-04 02:01:28 +00:00
|
|
|
|
2021-07-14 15:35:38 +00:00
|
|
|
for key, value in pairs(base_paths) do
|
|
|
|
if uv.fs_stat(value .. DIR_SEP .. bin) then
|
|
|
|
return true
|
2021-07-04 02:01:28 +00:00
|
|
|
end
|
2021-07-14 15:35:38 +00:00
|
|
|
end
|
|
|
|
return false
|
2021-03-10 12:15:06 +00:00
|
|
|
end
|
|
|
|
|
2021-07-04 02:01:28 +00:00
|
|
|
local function go_install(pkg)
|
|
|
|
local u = url[pkg]
|
2021-03-10 12:15:06 +00:00
|
|
|
if u == nil then
|
2021-12-22 03:34:10 +00:00
|
|
|
vim.notify("command " .. pkg .. " not supported, please update install.lua, or manually install it", vim.lsp.log_levels.WARN)
|
2021-03-10 12:15:06 +00:00
|
|
|
return
|
|
|
|
end
|
2021-04-23 06:31:00 +00:00
|
|
|
|
2021-07-04 02:01:28 +00:00
|
|
|
u = u .. "@latest"
|
2021-12-06 10:32:23 +00:00
|
|
|
local setup = { "go", "install", u }
|
2021-03-10 12:15:06 +00:00
|
|
|
|
2021-07-14 15:35:38 +00:00
|
|
|
vim.fn.jobstart(setup, {
|
|
|
|
on_stdout = function(c, data, name)
|
2021-12-06 10:32:23 +00:00
|
|
|
log(setup)
|
|
|
|
if type(data) == "table" and #data > 0 then
|
|
|
|
data = table.concat(data, " ")
|
|
|
|
end
|
|
|
|
|
|
|
|
local msg = "install " .. u .. " finished"
|
|
|
|
if #data > 1 then
|
|
|
|
msg = msg .. data
|
|
|
|
end
|
2021-12-22 03:34:10 +00:00
|
|
|
vim.notify(msg, vim.lsp.log_levels.DEBUG)
|
2021-12-06 10:32:23 +00:00
|
|
|
end,
|
2021-07-14 15:35:38 +00:00
|
|
|
})
|
2021-03-10 12:15:06 +00:00
|
|
|
end
|
|
|
|
|
2021-12-10 10:13:23 +00:00
|
|
|
local function install(bin, verbose)
|
2021-07-04 02:01:28 +00:00
|
|
|
if not is_installed(bin) then
|
2021-12-22 03:34:10 +00:00
|
|
|
vim.notify("installing " .. bin, vim.lsp.log_levels.INFO)
|
2021-07-04 02:01:28 +00:00
|
|
|
go_install(bin)
|
2021-12-06 10:32:23 +00:00
|
|
|
else
|
2021-12-10 10:13:23 +00:00
|
|
|
if verbose then
|
2021-12-22 03:34:10 +00:00
|
|
|
vim.notify(bin .. " already install, use GoUpdateBinary to update it", vim.lsp.log_levels.INFO)
|
|
|
|
end
|
2021-07-04 02:01:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function update(bin)
|
2021-07-14 15:35:38 +00:00
|
|
|
go_install(bin)
|
2021-07-04 02:01:28 +00:00
|
|
|
end
|
|
|
|
|
2021-03-10 12:15:06 +00:00
|
|
|
local function install_all()
|
|
|
|
for key, value in pairs(url) do
|
|
|
|
install(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-06 10:32:23 +00:00
|
|
|
local function update_all()
|
|
|
|
for key, value in pairs(url) do
|
|
|
|
update(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
install = install,
|
|
|
|
update = update,
|
|
|
|
install_all = install_all,
|
|
|
|
update_all = update_all,
|
|
|
|
gotools = gotools,
|
|
|
|
}
|