Increase reliability (#4)

* Add check to see if commands already exist

* Migrate to go install, as go get will be depricated

* Fix bug in comparison function

* Add installation instructions for $PATH

* remove old stuff

* remove backtick

* complete install

* remove unused function
pull/6/head
David Brouwer 3 years ago committed by GitHub
parent 6ac8755142
commit 9485e37cc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,16 @@ The plugin covers most features required for a gopher.
## install
make sure the `$GOPATH/bin` path is added to your `$PATH` environment variable. To check this you can run
```bash
echo $PATH | grep "$GOPATH/bin"
```
if nothing shows up, you can add the following to your shell config file
```bash
export PATH=$PATH:$GOPATH/bin
```
add 'ray-x/go.nvim' to your package manager, the dependency is `treesitter` (and optionally, treesitter-objects)
related binaries will be installed the first time you use it
Add format in your vimrc.

@ -15,13 +15,16 @@ function go.setup(cfg)
vim.cmd('command! Gofmt lua require("go.format").gofmt()')
vim.cmd('command! Goimport lua require("go.format").goimport()')
vim.cmd([[command GoBuild :setl makeprg=go\ build | :Gmake]])
vim.cmd([[command GoGenerate :setl makeprg=go\ generate | :Gmake]])
vim.cmd([[command GoRun :setl makeprg=go\ run | :Gmake]])
vim.cmd([[command GoTestFunc :Gmake -run ..]])
vim.cmd([[command GoTest :setl makeprg=go\ test\ ./... | :Gmake]])
vim.cmd([[command GoTestCompile setl makeprg=go\ build | :Gmake]])
local cmds = vim.api.nvim_get_commands({})
if cmds["GoBuild"] == nil then vim.cmd([[command GoBuild :setl makeprg=go\ build | :Gmake]]) end
if cmds["GoGenerate"] == nil then vim.cmd([[command GoGenerate :setl makeprg=go\ generate | :Gmake]]) end
if cmds["GoRun"] == nil then vim.cmd([[command GoRun :setl makeprg=go\ run | :Gmake]]) end
if cmds["GoTestFunc"] == nil then vim.cmd([[command GoTestFunc :Gmake -run ..]]) end
if cmds["GoTest"] == nil then vim.cmd([[command GoTest :setl makeprg=go\ test\ ./... | :Gmake]]) end
if cmds["GoTestCompile"] == nil then vim.cmd([[command GoTestCompile :setl makeprg=go\ build | :Gmake]]) end
vim.cmd([[command! GoAddTest lua require("go.gotests").fun_test()]])
vim.cmd([[command! GoAddExpTest lua require("go.gotests").exported_test()]])

@ -1,53 +1,39 @@
local uv = vim.loop
local gopath = vim.fn.expand("$GOPATH")
local gobinpath = gopath .. "/bin/"
local DIR_SEP = package.config:sub(1,1)
local url = {
golines = "segmentio/golines",
gofumpt = "mvdan/gofumpt",
gofumports = "mvdan/gofumpt",
gomodifytags = "fatih/gomodifytags",
gotsts = "cweill/gotests",
iferr = 'koron/iferr',
fillstruct = 'davidrjenni/reftools/cmd/fillstruct',
fixplurals = 'davidrjenni/reftools/cmd/fixplurals',
fillswitch = 'davidrjenni/reftools/cmd/fillswitch',
gofumpt = "mvdan.cc/gofumpt",
gofumports = "mvdan.cc/gofumpt",
golines = "github.com/segmentio/golines",
gomodifytags = "github.com/fatih/gomodifytags",
gotsts = "github.com/cweill/gotests",
iferr = 'github.com/koron/iferr',
fillstruct = 'github.com/davidrjenni/reftools/cmd/fillstruct',
fixplurals = 'github.com/davidrjenni/reftools/cmd/fixplurals',
fillswitch = 'github.com/davidrjenni/reftools/cmd/fillswitch',
}
local function install(bin)
local state = uv.fs_stat(gobinpath .. bin)
if not state then
print("installing " .. bin)
local u = url[bin]
if u == nil then
print("command " .. bin .. " not supported, please update install.lua")
return
end
u = 'github.com/' .. u
local setup = {
"go", "get",
u
}
vim.fn.jobstart(
setup,
-- setup.args,
{
on_stdout = function(c, data, name)
print(data)
local function is_installed(bin)
local env_path = os.getenv("PATH")
local base_paths = vim.split(env_path, ":", true)
for key, value in pairs(base_paths) do
if uv.fs_stat(value .. DIR_SEP .. bin) then
return true
end
}
)
end
end
return false
end
local function update(bin)
local u = url[bin]
local function go_install(pkg)
local u = url[pkg]
if u == nil then
print("command " .. bin .. " not supported, please update install.lua")
print("command " .. pkg .. " not supported, please update install.lua, or manually install it")
return
end
u = 'github.com/' .. u
local setup = {"go", "get", "-u", u}
u = u .. "@latest"
local setup = {"go", "install", u}
vim.fn.jobstart(
setup,
@ -59,6 +45,17 @@ local function update(bin)
)
end
local function install(bin)
if not is_installed(bin) then
print("installing " .. bin)
go_install(bin)
end
end
local function update(bin)
go_install(bin)
end
local function install_all()
for key, value in pairs(url) do
install(key)

@ -1,14 +1,14 @@
local util = {}
util.check_same = function(tbl1, tbl2)
if #tbl1 ~= #tbl2 then
return
return false
end
for k, v in ipairs(tbl1) do
if v ~= tbl2[k] then
return true
return false
end
end
return false
return true
end
util.copy_array = function(from, to)

Loading…
Cancel
Save