Merge branch 'master' into serverCapcities

pull/117/head
ray-x 2 years ago
commit e77920422e

@ -16,20 +16,23 @@ The plugin covers most features required for a gopher.
- Load vscode launch configuration
- Unit test: generate unit test framework with [gotests](https://github.com/cweill/gotests). Run test with
richgo/ginkgo/go test
- tag modify: Supports gomodifytags
- Code format: Supports LSP format and GoFmt
- Add and remove tag for struct with tag modify(gomodifytags)
- Code format: Supports LSP format and GoFmt(with golines)
- CodeLens : gopls codelens and codelens action support
- Comments: Add autodocument for your package/function/struct/interface. This feature is unique and can help you suppress golint
errors...
- Go to alternative go file (between test and source)
- Test with ginkgo, richgo inside floaterm (to enable floaterm, guihua.lua has to be installed)
- Go 1.18 support, configure your go to `go1.18` in config
- GoFixPlural, FixStruct, FxiSwitch, Add comment, IfErr, ModTidy, GoGet ... Most of the tools are built on top of
treesitter AST or go AST. It is fast and accurate.
## Installation
Use your favorite package manager to install. The dependency `treesitter` (and optionally, treesitter-objects)
should be installed the first time you use it.
Also Run `TSInstall go` to install the go parser if not installed yet.
`sed` is recommand to run this plugin.
### [vim-plug](https://github.com/junegunn/vim-plug)
@ -465,7 +468,7 @@ require('go').setup({
fillstruct = 'gopls', -- can be nil (use fillstruct, slower) and gopls
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 120, -- max line length in goline format
tag_transform = false, -- tag_transfer check gomodifytags for details
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
test_template = '', -- g:go_nvim_tests_template check gotests for details
test_template_dir = '', -- default to nil if not set; g:go_nvim_tests_template_dir check gotests for details
comment_placeholder = '' , -- comment_placeholder your cool placeholder e.g. ﳑ    
@ -503,6 +506,7 @@ require('go').setup({
build_tags = "tag1,tag2", -- set default build tags
textobjects = true, -- enable default text jobects through treesittter-text-objects
test_runner = 'go', -- richgo, go test, richgo, dlv, ginkgo
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = false, -- set to true to run in float window. :GoTermClose closes the floatterm
-- float term recommand if you use richgo/ginkgo with terminal color
})

@ -312,6 +312,7 @@ You can setup go.nvim with following options:
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" }
build_tags = "", --- you can provide extra build tags for tests or debugger
test_runner = "go", -- richgo, go test, richgo, dlv, ginkgo
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = false, -- set to true to run in float window.
}

@ -50,6 +50,7 @@ _GO_NVIM_CFG = {
build_tags = "", --- you can provide extra build tags for tests or debugger
textobjects = true, -- treesitter binding for text objects
test_runner = "go", -- richgo, go test, richgo, dlv, ginkgo
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = false, -- set to true to run in float window.
}
@ -131,7 +132,7 @@ function go.setup(cfg)
-- e.g. GoTestFile unit
vim.cmd([[command! -nargs=* GoTestFile lua require('go.gotest').test_file(<f-args>)]])
vim.cmd([[command! -nargs=* GoTestPkg lua require('go.gotest').test_package(<f-args>)]])
vim.cmd([[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package(<f-args>)]])
vim.cmd([[command! -nargs=* GoAddTest lua require("go.gotests").fun_test(<f-args>)]])
vim.cmd([[command! -nargs=* GoAddExpTest lua require("go.gotests").exported_test(<f-args>)]])
vim.cmd([[command! -nargs=* GoAddAllTest lua require("go.gotests").all_test(<f-args>)]])

@ -159,6 +159,7 @@ function test_arg(arg)
local optarg
local optind
arg = arg or { "-t", "-r", "-c", "path1", "-g", "unit,integration", "path" }
-- arg = arg or { "-t", "-r", "-c", "-g", "unit,integration" }
opts, optind, optarg, unparsed = alt_getopt.get_ordered_opts(arg, "cg:hvo:n:rS:st", long_opts)
print("ordered opts")

@ -78,13 +78,15 @@ local function run_test(path, args)
local bench = false
local optarg, optind, reminder = getopt.get_opts(args, short_opts, long_opts)
if optarg["c"] then
path = "." .. sep .. vim.fn.expand("%:h") -- vim.fn.expand("%:p:h") can not resolve releative path
path = utils.rel_path() -- vim.fn.expand("%:p:h") can not resolve releative path
compile = true
end
if optarg["b"] then
bench = true
end
if next(reminder) then
path = reminder[1]
end
local test_runner = _GO_NVIM_CFG.go
if _GO_NVIM_CFG.test_runner ~= test_runner then
test_runner = _GO_NVIM_CFG.test_runner
@ -94,12 +96,16 @@ local function run_test(path, args)
local tags = get_build_tags(args)
log(tags)
local cmd
local cmd = {}
if _GO_NVIM_CFG.run_in_floaterm then
cmd = { test_runner, "test", "-v" }
else
cmd = { "-v" }
table.insert(cmd, test_runner)
table.insert(cmd, "test")
end
if _GO_NVIM_CFG.verbose_tests then
table.insert(cmd, "-v")
end
if not empty(tags) then
cmd = vim.list_extend(cmd, tags)
end
@ -171,10 +177,8 @@ M.test_package = function(...)
local args = { ... }
log(args)
local repath = utils.rel_path() or ""
local repath = utils.rel_path() or "."
local fpath = repath .. utils.sep() .. "..."
utils.log("fpath: " .. fpath)
-- args[#args + 1] = fpath
@ -210,13 +214,17 @@ M.test_fun = function(...)
end
end
local cmd
local cmd = {}
local run_in_floaterm = optarg["F"] or _GO_NVIM_CFG.run_in_floaterm
if run_in_floaterm then
cmd = { test_runner, "test", "-v" }
else
cmd = { "-v" }
table.insert(cmd, test_runner)
table.insert(cmd, "test")
end
if _GO_NVIM_CFG.verbose_tests then
table.insert(cmd, "-v")
end
if not empty(tags) then
cmd = vim.list_extend(cmd, tags)
end
@ -286,13 +294,16 @@ M.test_file = function(...)
local relpath = utils.rel_path()
local cmd_args
local cmd_args = {}
if run_in_floaterm then
cmd_args = { test_runner, "test", "-v" }
else
cmd_args = { "-v" }
table.insert(cmd_args, test_runner)
table.insert(cmd_args, "test")
end
if _GO_NVIM_CFG.verbose_tests then
table.insert(cmd_args, "-v")
end
if tags ~= nil and #tags > 1 then
cmd_args = vim.list_extend(cmd_args, tags)
end

@ -32,6 +32,12 @@ local function binary_check()
if no_err then
ok("All binaries installed")
end
if vim.fn.executable('sed') == 1 then
info("sed installed.")
else
warn("sed is not installed.")
end
end
local function plugin_check()

@ -43,8 +43,8 @@ tags.modify = function(...)
table.insert(setup, struct_name)
end
if transform then
table.insert(setup.args, "-transform")
table.insert(setup.args, transform)
table.insert(setup, "-transform")
table.insert(setup, transform)
end
local arg = { ... }
for i, v in ipairs(arg) do

@ -415,10 +415,11 @@ end
function util.rel_path()
local fpath = vim.fn.expand("%:p:h")
local workfolders = vim.lsp.buf.list_workspace_folders()
if workfolder ~= nil then
fpath = "." .. fpath:sub(#workfolder + 1)
if workfolders ~= nil and next(workfolders) then
fpath = "." .. fpath:sub(#workfolders[1] + 1)
end
return fpath
end

@ -41,6 +41,7 @@ require('go').setup({
dap_debug_vt = true, -- set to true to enable dap virtual text
test_runner = 'richgo', -- richgo, go test, richgo, dlv, ginkgo
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = true -- set to true to run in float window.
})
EOF

Loading…
Cancel
Save