updates for dap.ui

pull/46/head
ray-x 3 years ago
parent ef332025ce
commit 1b11f52b08

@ -20,6 +20,7 @@ The plugin covers most features required for a gopher.
- 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)
## install
@ -123,16 +124,18 @@ textobjects. Also with treesitter-objects, you can move, swap the selected block
## Build and test
| command | Description |
| --------------- | ------------------------------------------------------------------------ |
| GoMake | make |
| GoBuild | |
| GoGenerate | |
| GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` |
| GoTest | go test ./... |
| GoTest yourtags | go test ./... -tags=yourtags |
| GoLint | golangci-lint |
| GoCoverage | go test -coverprofile |
| command | Description |
| --------------------------------------------- | ------------------------------------------------------------------------ |
| GoMake | make |
| GoBuild | |
| GoGenerate | |
| GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` |
| GoTest | go test ./... |
| GoTest -tags=yourtags | go test ./... -tags=yourtags |
| GoTest package_path -tags=yourtags | go test packagepath -tags=yourtags |
| GoTest package_path -tags=yourtags other_args | go test packagepath -tags=yourtags other_args |
| GoLint | golangci-lint |
| GoCoverage | go test -coverprofile |
Show test coverage:
@ -146,15 +149,20 @@ granularities.
Support table based unit test auto generate, parse current function/method name using treesitter
| command | Description |
| ------------------ | ------------------------------------------------------- |
| GoTestFunc | run test for current func |
| GoTestFunc yourtag | run test for current func with `-tags yourtag` option |
| GoTestFile | run test for current file folder |
| GoTestFile yourtag | run test for current folder with `-tags yourtag` option |
| GoAddTest | |
| GoAddExpTest | Add tests for exported funcs |
| GoAddAllTest | Add tests for all funcs |
| command | Description |
| ------------------------ | ------------------------------------------------------- |
| GoTestFunc | run test for current func |
| GoTestFunc -tags=yourtag | run test for current func with `-tags yourtag` option |
| GoTestFile | run test for current file |
| GoTestFile -tags=yourtag | run test for current folder with `-tags yourtag` option |
| GoTestPkg | run test for current package/folder |
| GoTestPkg -tags=yourtag | run test for current folder with `-tags yourtag` option |
| GoAddTest | |
| GoAddExpTest | Add tests for exported funcs |
| GoAddAllTest | Add tests for all funcs |
Note: For GoTestXXX
You can add avaliable arguments e.g. `GoTest -tags=integration ./internal/web -bench=. -count=1 -`
## GoDoc
@ -343,6 +351,9 @@ require('go').setup({
fillstruct = 'gopls', -- can be nil (use fillstruct, slower) and gopls
lsp_diag_hdlr = true, -- hook lsp diag handler
dap_debug = true, -- set to false to disable dap
test_runner = 'go', -- richgo, go test, richgo, dlv, ginkgo
run_in_floaterm = false, -- set to true to run in float window.
--float term recommand if you use richgo/ginkgo with terminal color
dap_debug_keymap = true, -- set keymaps for debugger
dap_debug_gui = true, -- set to true to enable dap gui, highly recommand
dap_debug_vt = true, -- set to true to enable dap virtual text
@ -480,6 +491,7 @@ Plug 'nvim-treesitter/nvim-treesitter'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'theHamsta/nvim-dap-virtual-text'
Plug 'ray-x/guihua.lua' --float term, gui support
Plug 'ray-x/go.nvim'

@ -23,7 +23,10 @@ _GO_NVIM_CFG = {
dap_debug_gui = true,
dap_vt = true, -- false, true and 'all frames'
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
build_tags = "", --- you can provide extra build tags for tests or debugger
test_runner = 'go', -- richgo, go test, richgo, dlv, ginkgo
run_in_floaterm = false -- set to true to run in float window.
}
local dap_config = function()
@ -75,8 +78,11 @@ function go.setup(cfg)
local sep = require('go.utils').sep()
-- example to running test in split buffer
-- vim.cmd(
-- [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTest :setl makeprg=go\ test\ -v\ | lua require'go.runner'.make(<f-args>)]])
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTest :setl makeprg=go\ test\ -v\ | lua require'go.runner'.make(<f-args>)]])
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTest lua require('go.gotest').test(<f-args>)]])
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoCoverage lua require'go.coverage'.run(<f-args>)]])
@ -88,6 +94,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! GoAddTest lua require("go.gotests").fun_test()]])
vim.cmd([[command! GoAddExpTest lua require("go.gotests").exported_test()]])
vim.cmd([[command! GoAddAllTest lua require("go.gotests").all_test()]])
@ -150,4 +157,16 @@ end
go.doc_complete = require'go.godoc'.doc_complete
go.package_complete = require'go.package'.complete
go.set_test_runner = function(runner)
-- richgo, go test, richgo, dlv, ginkgo
local runners = {"richgo", "go", "richgo", "ginkgo"} -- dlv
for _, v in pairs(runners) do
if v == runner then
_GO_NVIM_CFG.test_runner = runner
return
end
end
print("runner not supported " .. runner)
end
return go

@ -1,4 +1,5 @@
local log = require('go.utils').log
local utils = require('go.utils')
local log = utils.log
local coverage = {}
local api = vim.api
local M = {}
@ -174,13 +175,17 @@ local function parse_line(line)
end
if vim.tbl_isempty(vim.fn.sign_getdefined(sign_covered)) then
vim.fn.sign_define(sign_covered,
{text = _GO_NVIM_CFG.gocoverage_sign, texthl = "goCoverageCovered"})
vim.fn.sign_define(sign_covered, {
text = _GO_NVIM_CFG.gocoverage_sign,
texthl = "goCoverageCovered"
})
end
if vim.tbl_isempty(vim.fn.sign_getdefined(sign_uncover)) then
vim.fn.sign_define(sign_uncover,
{text = _GO_NVIM_CFG.gocoverage_sign, texthl = "goCoverageUncover"})
vim.fn.sign_define(sign_uncover, {
text = _GO_NVIM_CFG.gocoverage_sign,
texthl = "goCoverageUncover"
})
end
M.read_cov = function(covfn)
@ -213,26 +218,61 @@ M.read_cov = function(covfn)
return coverage
end
M.run = function(tag)
M.run = function(...)
local get_build_tags = require('go.gotest').get_build_tags
-- local cov = vim.fn.tempname()
local cov = vim.fn.expand("%:p:h") .. "/cover.cov"
local cmd = {'go', 'test', '-coverprofile', cov}
if tag ~= nil then
table.insert(cmd, tag)
local args = {...}
log(args)
local test_runner = 'go'
if _GO_NVIM_CFG.test_runner ~= 'go' then
test_runner = _GO_NVIM_CFG.test_runner
require("go.install").install(test_runner)
end
local cmd = {test_runner, 'test', '-coverprofile', cov}
local tags = ''
local args2 = {}
if args ~= nil and args ~= {} then
tags, args2 = get_build_tags(args)
if tags ~= '' then
vim.list_extend(cmd, {tags})
end
vim.list_extend(cmd, args2)
end
local lines = {""}
coverage = {}
table.insert(cmd, "./" .. vim.fn.expand('%:.:h'))
if args == {} then
-- pkg provided?
table.insert(cmd, "." .. utils.spe() .. vim.fn.expand('%:.:h'))
end
log("run coverage", cmd)
local argsstr = ''
if _GO_NVIM_CFG.run_in_floaterm then
cmd = table.concat(cmd, " ")
if args2 == {} then
cmd = cmd .. '.' .. utils.sep() .. '...'
end
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
local j = vim.fn.jobstart(cmd, {
on_stdout = function(jobid, data, event)
log("go coverage " .. vim.inspect(data))
vim.list_extend(lines, data)
end,
on_stderr = function(job_id, data, event)
print("go coverage finished with message: " .. vim.inspect(tag) .. "error: "
.. vim.inspect(data) .. "job" .. tostring(job_id) .. "ev" .. event)
print("go coverage finished with message: " .. vim.inspect(tag) .. "error: " .. vim.inspect(data) .. "job"
.. tostring(job_id) .. "ev" .. event)
end,
on_exit = function(job_id, data, event)
if event ~= "exit" then

@ -29,12 +29,22 @@ local function keybind()
["n|D"] = map_cr('<cmd>lua require"dap".down()<CR>'):with_noremap():with_silent(),
["n|C"] = map_cr('<cmd>lua require"dap".run_to_cursor()<CR>'):with_noremap():with_silent(),
["n|b"] = map_cr('<cmd>lua require"dap".toggle_breakpoint()<CR>'):with_noremap():with_silent(),
["n|P"] = map_cr('<cmd>lua require"dap".pause()<CR>'):with_noremap():with_silent(),
["n|p"] = map_cr('<cmd>lua require"dap.ui.variables".hover()<CR>'):with_noremap():with_silent(),
["v|p"] = map_cr('<cmd>lua require"dap.ui.variables".visual_hover()<CR>'):with_noremap():with_silent()
["n|P"] = map_cr('<cmd>lua require"dap".pause()<CR>'):with_noremap():with_silent()
--
}
if _GO_NVIM_CFG.dap_debug_gui then
keys["n|p"] = map_cr('<cmd>lua require("dapui").eval()'):with_noremap():with_silent()
keys["v|p"] = map_cr('<cmd>lua require("dapui").eval()'):with_noremap():with_silent()
keys["n|K"] = map_cr('<cmd>lua require("dapui").float_element()'):with_noremap():with_silent()
keys["n|B"] = map_cr('<cmd>lua require("dapui").float_element("breakpoints")'):with_noremap():with_silent()
keys["n|R"] = map_cr('<cmd>lua require("dapui").float_element("repl")'):with_noremap():with_silent()
keys["n|O"] = map_cr('<cmd>lua require("dapui").float_element("scopes")'):with_noremap():with_silent()
keys["n|a"] = map_cr('<cmd>lua require("dapui").float_element("stacks")'):with_noremap():with_silent()
keys["n|w"] = map_cr('<cmd>lua require("dapui").float_element("watches")'):with_noremap():with_silent()
else
keys["n|p"] = map_cr('<cmd>lua require"dap.ui.widgets".hover()<CR>'):with_noremap():with_silent()
keys["v|p"] = map_cr('<cmd>lua require"dap.ui.widgets".hover()<CR>'):with_noremap():with_silent()
end
bind.nvim_load_mapping(keys)
end
@ -50,11 +60,24 @@ end
local M = {}
M.prepare = function()
vim.g.dap_virtual_text = 'all frames'
utils.load_plugin('nvim-dap', "dap")
vim.fn.sign_define('DapBreakpoint', {
text = _GO_NVIM_CFG.icons.breakpoint,
texthl = '',
linehl = '',
numhl = ''
})
vim.fn.sign_define('DapStopped', {
text = _GO_NVIM_CFG.icons.currentpos,
texthl = '',
linehl = '',
numhl = ''
})
if _GO_NVIM_CFG.dap_debug_gui then
utils.load_plugin('nvim-dap-ui', "dapui")
utils.load_plugin('nvim-dap-virtual-text')
local vt = utils.load_plugin('nvim-dap-virtual-text')
vt.setup({enabled_commands = true, all_frames = true})
end
end
@ -154,7 +177,9 @@ M.run = function(...)
end
M.stop = function()
local keys = {"r", "c", "n", "s", "o", "S", "u", "D", "C", "b", "P", "p"}
local keys = {
"r", "c", "n", "s", "o", "S", "u", "D", "C", "b", "P", "p", "K", "B", "R", "O", "a", "w"
}
for _, value in pairs(keys) do
local cmd = "silent! unmap " .. value
vim.cmd(cmd)

@ -0,0 +1,120 @@
-- gonkgo test
local M = {}
local utils = require("go.utils")
local log = utils.log
local function get_build_tags(args)
local tags = {}
if args ~= nil then
table.insert(tags, args)
end
if _GO_NVIM_CFG.build_tags ~= "" then
table.insert(tags, _GO_NVIM_CFG.build_tags)
end
if #tags == 0 then
return ""
end
return [[-tags\ ]] .. table.concat(tags, ",") .. [[\ ]]
end
local function find_describe(lines)
local describe
local pat = [[Describe%(%".*%",%sfunc]]
local despat = [[%(%".*%"]]
for i = #lines, 1, -1 do
local line = lines[i]
local fs, fe = string.find(line, pat)
if fs then
line = string.sub(line, fs + #"Describe", fe)
fs, fe = string.find(line, despat)
if fs ~= nil then
if fe - fs <= 2 then
return nil
end
describe = line:sub(fs + 2, fe - 1)
return describe
end
end
end
return nil
end
-- print(find_describe({
-- [[ var _ = Describe("Integration test hourly data EstimateCombinedRules without ws ID", func() { ]]
-- }))
-- Run with ginkgo Description
M.test_fun = function(...)
local args = {...}
log(args)
local fpath = vim.fn.expand('%:p:h')
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row, col = row, col + 1
local fnum = row - 3
if fnum < 0 then
fnum = 0
end
local lines = vim.api.nvim_buf_get_lines(0, fnum, row + 1, true)
local describe = find_describe(lines)
log("testing: ", describe)
if describe == nil then
log("failed to find test function, test file instead")
return M.test_file(args)
end
local test_runner = 'ginkgo'
require("go.install").install(test_runner)
if _GO_NVIM_CFG.run_in_floaterm then
local cmd = test_runner .. [[ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[ ]] .. fpath
log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
local cmd = [[setl makeprg=]] .. test_runner .. [[\ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[\ ]]
.. fpath .. [[ | lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
return true
end
M.test_file = function(...)
local args = {...}
log(args)
-- require sed
local fpath = vim.fn.expand('%:p:h')
local fname = vim.fn.expand('%:p')
log(fpath, fname)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
fname = "." .. fname:sub(#workfolder + 1)
log(workfolder, fname)
local test_runner = 'ginkgo'
require("go.install").install(test_runner)
if _GO_NVIM_CFG.run_in_floaterm then
cmd = test_runner .. [[ --regexScansFilePath=true ]] .. get_build_tags(args) .. [[ --focus ]] .. fname .. " "
.. fpath
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
fname = utils.relative_to_cwd(fname) .. [[\ ]]
local cmd = [[setl makeprg=ginkgo\ ]] .. get_build_tags(args) .. [[\ --regexScansFilePath=true\ --focus\ ]] .. fname
.. fpath .. [[| lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end
return M

@ -1,25 +1,127 @@
local M = {}
local utils = require("go.utils")
local log = utils.log
local ginkgo = require("go.ginkgo")
local function get_build_tags(args)
local tags = {}
local tags = "-tags"
if args ~= nil then
table.insert(tags, args)
if _GO_NVIM_CFG.build_tags ~= "" then
tags = tags .. _GO_NVIM_CFG.build_tags
end
if _GO_NVIM_CFG.build_tags ~= "" then
table.insert(tags, _GO_NVIM_CFG.build_tags)
for i, value in pairs(args) do
if value:find('-tags') then
if tags == '-tags' then
tags = value
else
tags = tags .. ',' .. value:sub(#'-tags=' + 1)
end
table.remove(args, i)
break
end
end
if tags == '-tags' then
tags = ''
end
return tags, args
end
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
test_runner = _GO_NVIM_CFG.test_runner
require("go.install").install(test_runner)
end
if #tags == 0 then
return ""
local tags, args2 = get_build_tags(args)
local argsstr = ""
if _GO_NVIM_CFG.run_in_floaterm then
argsstr = table.concat(args2 or {}, " ")
if argsstr == "" then
argsstr = '.' .. utils.sep() .. '...'
end
local cmd = test_runner .. [[ test ]] .. tags .. [[ -v ]] .. argsstr
cmd = cmd .. tags .. [[ -v ]] .. argsstr
if path ~= '' then
cmd = cmd .. [[ ]] .. path
end
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
argsstr = table.concat(args2 or {}, [[\ ]])
if argsstr == "" then
argsstr = '.' .. utils.sep() .. '...'
end
local cmd = [[setl makeprg=go\ test\ ]] .. tags .. [[\ -v\ ]] .. argsstr .. [[\ ]]
.. path [[| lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end
M.test = function(...)
local args = {...}
log(args)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
if workfolder == nil then
workfolder = "."
end
local fpath = workfolder .. utils.sep() .. '...'
-- local fpath = workfolder .. utils.sep() .. '...'
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
run_test(fpath, args)
end
M.test_suit = function(...)
local args = {...}
log(args)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
utils.log(args)
local fpath = workfolder .. utils.sep() .. '...'
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
run_test(fpath, args)
end
M.test_package = function(...)
local args = {...}
log(args)
local repath = utils.rel_path() or ''
local fpath = repath .. utils.sep() .. '...'
utils.log("fpath" .. fpath)
utils.log("fpath" .. fpath)
args[#args + 1] = fpath
run_test(fpath, args)
return [[-tags\ ]] .. table.concat(tags, ",") .. [[\ ]]
end
M.test_fun = function(args)
M.test_fun = function(...)
local args = {...}
log(args)
-- for i, v in ipairs(args) do
-- table.insert(setup, v)
-- end
local fpath = vim.fn.expand('%:p:h')
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
@ -29,23 +131,121 @@ M.test_fun = function(args)
return false
end
local tags, args2 = get_build_tags(args)
local argsstr = ""
utils.log("parnode" .. vim.inspect(ns))
local cmd = [[setl makeprg=go\ test\ ]] .. get_build_tags(args) .. [[-v\ -run\ ^]] .. ns.name .. [[\ ]] .. fpath
.. [[ | lua require"go.asyncmake".make()]]
local test_runner = 'go'
if _GO_NVIM_CFG.test_runner ~= 'go' then
test_runner = _GO_NVIM_CFG.test_runner
if test_runner == 'ginkgo' then
ginkgo.test_fun(...)
end
require("go.install").install(test_runner)
end
local bench = ''
if ns.name:find("Bench") then
bench = "-bench=" .. ns.name
end
if _GO_NVIM_CFG.run_in_floaterm then
argsstr = table.concat(args2 or {}, " ")
local cmd = test_runner .. [[ test ]] -- .. tags .. [[-v -run ^]] .. ns.name .. [[ ]] .. argstr .. [[ ]] .. fpath
if tags ~= "" then
cmd = cmd .. tags
end
cmd = cmd .. [[-v -run ^]] .. ns.name
if bench ~= '' then
cmd = cmd .. [[ ]] .. bench
end
if argsstr ~= "" then
cmd = cmd .. [[ ]] .. argsstr
end
cmd = cmd .. [[ ]] .. fpath
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
argsstr = table.concat(args2 or {}, [[\ ]])
-- local cmd =
-- [[setl makeprg=]] .. test_runner .. [[\ test\ ]] .. tags .. [[-v\ -run\ ^]] .. ns.name .. [[\ ]] .. argsstr
-- .. [[\ ]] .. fpath .. [[ | lua require"go.asyncmake".make()]]
--
local cmd = [[setl makeprg=]] .. test_runner .. [[\ test\ ]]
if tags ~= "" then
cmd = cmd .. tags
end
cmd = cmd .. [[-v\ -run\ ^]] .. ns.name
if bench ~= '' then
cmd = cmd .. [[\ ]] .. bench
end
if argsstr ~= "" then
cmd = cmd .. [[\ ]] .. argsstr
end
cmd = cmd .. [[\ ]] .. fpath .. [[ | lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
return true
end
M.test_file = function(args)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
local tag = ''
M.test_file = function(...)
local args = {...}
log(args)
-- require sed
-- local testcases = [[sed -n 's/func.*\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\\|/g']]
utils.log(args)
local fpath = vim.fn.expand("%:p:h") .. '/..'
local fname = vim.fn.expand('%:p')
local cmd = [[cat ]] .. fname .. [[| sed -n 's/func.*\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\\|/g']]
-- TODO maybe with treesitter or lsp list all functions in current file and regex with Test
local tests = vim.fn.systemlist(cmd)[1]
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
local cmd = [[setl makeprg=go\ test\ ]] .. get_build_tags(args) .. [[-v\ -run\ ]] .. fpath
.. [[| lua require"go.asyncmake".make()]]
utils.log(tests)
local tags, args2 = get_build_tags(args)
local argsstr = ""
local test_runner = 'go'
if _GO_NVIM_CFG.test_runner ~= 'go' then
test_runner = _GO_NVIM_CFG.test_runner
if test_runner == 'ginkgo' then
ginkgo.test_fun(...)
end
require("go.install").install(test_runner)
end
local relpath = utils.rel_path()
if _GO_NVIM_CFG.run_in_floaterm then
argsstr = table.concat(args2 or {} or {}, " ")
cmd = test_runner .. [[ test ]] .. tags .. [[-v -run ]] .. tests .. [[ ]] .. argsstr .. [[ ]] .. relpath
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
return
end
argsstr = table.concat(args2 or {}, [[\ ]])
cmd = [[setl makeprg=go\ test\ ]] .. tags .. [[-v\ -run\ ]] .. tests .. [[\ ]] .. argsstr .. [[\ ]] .. relpath
.. [[| lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end

@ -12,7 +12,10 @@ local url = {
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'
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'
}
local function is_installed(bin)

@ -27,5 +27,13 @@ return {
table.insert(pkgs, util.relative_to_cwd(curpkg))
end
return table.concat(pkgs, '\n')
end,
all_pkgs = function()
local ok, l = golist(false, {util.all_pkgs()})
if not ok then
log('Failed to find all packages for current module/project.')
end
return l
end
}

@ -0,0 +1,56 @@
local utils = require 'go.utils'
local api = vim.api
local guihua_term = utils.load_plugin('guihua.lua', 'guihua.floating')
if not guihua_term then
utils.warn('guihua not installed, please install ray-x/guihua.lua for GUI functions')
end
local function close_float_terminal()
local has_var, float_term_win = pcall(api.nvim_buf_get_var, 0, 'go_float_terminal_win')
if not has_var then
return
end
if float_term_win[1] ~= nil and api.nvim_buf_is_valid(float_term_win[1]) then
api.nvim_buf_delete(float_term_win[1], {force = true})
end
if float_term_win[2] ~= nil and api.nvim_win_is_valid(float_term_win[2]) then
api.nvim_win_close(float_term_win[2], true)
end
end
local term = function(opts)
local columns = api.nvim_get_option("columns")
local lines = api.nvim_get_option("lines")
local win_width, win_height
if columns > 130 then
-- split in right
win_height = math.ceil(lines * 0.98)
win_width = math.ceil(columns * 0.3)
opts.y = win_height
opts.x = columns - win_width
else
win_height = math.ceil(lines * 0.3)
win_width = math.ceil(columns * 0.98)
opts.y = opts.y or lines - win_height
opts.x = opts.x or 1
end
opts.win_height = opts.win_height or win_height
opts.win_width = opts.win_width or win_width
opts.border = opts.border or 'single'
if opts.autoclose == nil then
opts.autoclose = true
end
local buf, win, closer = guihua_term.floating_term(opts)
api.nvim_command('setlocal nobuflisted')
api.nvim_buf_set_var(buf, 'go_float_terminal_win', {buf, win})
return buf, win, closer
end
-- term({cmd = 'echo abddeefsfsafd', autoclose = false})
return {run = term, close = close_float_terminal}

@ -240,7 +240,7 @@ function util.load_plugin(name, modulename)
has, plugin = pcall(require, modulename)
if not has then
print("plugin failed to load " .. name)
util.warn("plugin failed to load " .. name)
end
return plugin
end
@ -296,4 +296,13 @@ function util.info(msg)
vim.api.nvim_echo({{"Info: " .. msg}}, true, {})
end
function util.rel_path()
local fpath = vim.fn.expand('%:p:h')
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
if workfolder ~= nil then
fpath = "." .. fpath:sub(#workfolder + 1)
end
return fpath
end
return util

Loading…
Cancel
Save