go 1.18beta

pull/74/head
ray-x 2 years ago
parent 60e0659d50
commit 0493df8b44

@ -404,6 +404,7 @@ Configure from lua suggested, The default setup:
```lua
require('go').setup({
go='go', -- go command, can be go[default] or go1.18beta1
goimport='gopls', -- goimport command, can be gopls[default] or goimport
fillstruct = 'gopls', -- can be nil (use fillstruct, slower) and gopls
gofmt = 'gofumpt', --gofmt cmd,

@ -4,6 +4,7 @@ local go = {}
-- Keep this in sync with README.md
-- Keep this in sync with doc/go.txt
_GO_NVIM_CFG = {
go = "go", -- set to go1.18beta1 if necessary
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
fillstruct = "gopls",
gofmt = "gofumpt", -- if set to gopls will use gopls format
@ -15,13 +16,14 @@ _GO_NVIM_CFG = {
verbose = false,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
lsp_cfg = false, -- false: do nothing
-- true: apply non-default gopls setup defined in go/lsp.lua
-- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g.
-- true: apply non-default gopls setup defined in go/lsp.lua
-- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g.
lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua for gopls,
-- when lsp_cfg is true
-- if lsp_on_attach is a function: use this function as on_attach function for gopls,
-- when lsp_cfg is true
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_codelens = true,
lsp_diag_hdlr = true, -- hook lsp diag handler
gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" }
@ -64,17 +66,24 @@ function go.setup(cfg)
vim.cmd([[command! GoFmt lua require("go.format").gofmt()]])
vim.cmd([[command! -nargs=* GoImport lua require("go.format").goimport(<f-args>)]])
vim.cmd([[command! GoGenerate :setl makeprg=go\ generate | :GoMake]])
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoBuild :setl makeprg=go\ build | lua require'go.asyncmake'.make(<f-args>)]]
local gobin = _GO_NVIM_CFG.go
local cmd = string.format([[command! GoGenerate :setl makeprg=%s\ generate | :GoMake]], gobin)
vim.cmd(cmd)
cmd = string.format(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoBuild :setl makeprg=%s\ build | lua require'go.asyncmake'.make(<f-args>)]],
gobin
)
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoVet :setl makeprg=go\ vet | lua require'go.asyncmake'.make(<f-args>)]]
vim.cmd(cmd)
cmd = string.format(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoVet :setl makeprg=%s\ vet | lua require'go.asyncmake'.make(<f-args>)]],
gobin
)
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoRun :setl makeprg=go\ run | lua require'go.asyncmake'.make(<f-args>)]]
vim.cmd(cmd)
cmd = string.format(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoRun :setl makeprg=%s\ run | lua require'go.asyncmake'.make(<f-args>)]],
gobin
)
vim.cmd(cmd)
-- if you want to output to quickfix
-- vim.cmd(
-- [[command! -nargs=* GoTest :setl makeprg=go\ test\ -v\ ./...| lua require'go.asyncmake'.make(<f-args>)]])

@ -58,8 +58,8 @@ M.get_build_tags = get_build_tags
local function run_test(path, args)
log(args)
local test_runner = "go"
if _GO_NVIM_CFG.test_runner ~= "go" then
local test_runner = _GO_NVIM_CFG.go
if _GO_NVIM_CFG.test_runner ~= test_runner then
test_runner = _GO_NVIM_CFG.test_runner
require("go.install").install(test_runner)
end
@ -92,7 +92,7 @@ local function run_test(path, args)
return
end
vim.cmd([[setl makeprg=go\ test]])
vim.cmd([[setl makeprg=]] .. _GO_NVIM_CFG.go .. [[\ test]])
utils.log("test cmd", cmd)
require("go.asyncmake").make(unpack(cmd))
@ -157,7 +157,7 @@ M.test_fun = function(...)
local argsstr = ""
utils.log("parnode" .. vim.inspect(ns))
local test_runner = "go"
local test_runner = _GO_NVIM_CFG.go
if _GO_NVIM_CFG.test_runner ~= "go" then
require("go.install").install(test_runner)
@ -228,7 +228,7 @@ M.test_file = function(...)
local tags, args2 = get_build_tags(args)
local test_runner = "go"
local test_runner = _GO_NVIM_CFG.go
if _GO_NVIM_CFG.test_runner ~= "go" then
test_runner = _GO_NVIM_CFG.test_runner
require("go.install").install(test_runner)
@ -263,7 +263,7 @@ M.test_file = function(...)
return
end
vim.cmd([[setl makeprg=go\ test]])
vim.cmd([[setl makeprg=]] .. _GO_NVIM_CFG.go .. [[\ test]])
require("go.asyncmake").make(unpack(cmd_args))
utils.log("test cmd", cmd)
end

@ -35,9 +35,9 @@ end
function util.root_dirs()
local dirs = {}
local root = vim.fn.systemlist({ "go", "env", "GOROOT" })
local root = vim.fn.systemlist({ _GO_NVIM_CFG.go, "env", "GOROOT" })
table.insert(dirs, root[1])
local paths = vim.fn.systemlist({ "go", "env", "GOPATH" })
local paths = vim.fn.systemlist({ _GO_NVIM_CFG.go, "env", "GOPATH" })
local sp = get_path_sep()
paths = vim.split(paths[1], sp)
@ -94,7 +94,7 @@ end
-- endfunction
function util.interface_list(pkg)
local p = vim.fn.systemlist({ "go", "doc", pkg })
local p = vim.fn.systemlist({ _GO_NVIM_CFG.go, "doc", pkg })
util.log(p)
local ifaces = {}
if p then
@ -114,20 +114,26 @@ function util.interface_list(pkg)
end
local function smartrun()
local cmd
if has_main() then
-- Found main function in current buffer
vim.cmd("lcd %:p:h | :set makeprg=go\\ run\\ . | :make | :lcd -")
cmd = string.format("lcd %:p:h | :set makeprg=%s\\ run\\ . | :make | :lcd -", _GO_NVIM_CFG.go)
vim.cmd(cmd)
else
vim.cmd("setl makeprg=go\\ run\\ . | :make")
cmd = string.format("setl makeprg=%s\\ run\\ . | :make", _GO_NVIM_CFG.go)
vim.cmd(cmd)
end
end
local function smartbuild()
local cmd
if has_main() then
-- Found main function in current buffer
vim.cmd("lcd %:p:h | :set makeprg=go\\ build\\ . | :make | :lcd -")
cmd = string.format("lcd %:p:h | :set makeprg=%s\\ build\\ . | :make | :lcd -", _GO_NVIM_CFG.go)
vim.cmd(cmd)
else
vim.cmd("setl makeprg=go\\ build\\ . | :make")
cmd = string.format("setl makeprg=%s\\ build\\ . | :make", _GO_NVIM_CFG.go)
vim.cmd(cmd)
end
end

Loading…
Cancel
Save