feat: default build tags (#38)

* feat: default build tags

Added option to specify default build tags for test and debugger.

* Update dap.lua

check   if _GO_NVIM_CFG.build_tags ~= "" then

Co-authored-by: Ales Brelih <ales.brelih@3fs.si>
Co-authored-by: rayx <rayx.cn@gmail.com>
pull/41/head
Aleš Brelih 3 years ago committed by GitHub
parent 37a4cfb1ad
commit d9f44a9320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,7 +22,8 @@ _GO_NVIM_CFG = {
dap_debug = true,
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" }
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
}
local dap_config = function()

@ -41,6 +41,14 @@ local function keybind()
end
local function get_build_flags()
if _GO_NVIM_CFG.build_tags ~= "" then
return "-tags " .. _GO_NVIM_CFG.build_tags
else
return ""
end
end
local M = {}
M.prepare = function()
@ -109,9 +117,12 @@ M.run = function(...)
type = "go",
name = "Debug",
request = "launch",
dlvToolPath = vim.fn.exepath("dlv")
dlvToolPath = vim.fn.exepath("dlv"),
buildFlags = get_build_flags()
}
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row, col = row, col + 1
@ -174,6 +185,7 @@ function M.ultest_post()
end
args[#args + 1] = arg
end
return {
dap = {
type = "go",
@ -181,7 +193,8 @@ function M.ultest_post()
mode = "test",
program = "./${relativeFileDirname}",
dlvToolPath = vim.fn.exepath("dlv"),
args = args
args = args,
buildFlags = get_build_flags()
},
parse_result = function(lines)
return lines[#lines] == "FAIL" and 1 or 0

@ -1,6 +1,24 @@
local M = {}
local utils = require("go.utils")
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
M.test_fun = function(args)
local fpath = vim.fn.expand('%:p:h')
@ -11,14 +29,8 @@ M.test_fun = function(args)
return
end
local tag = ''
utils.log(args)
if args ~= nil then
tag = [[-tags\ ]] .. args .. [[\ ]]
end
utils.log("parnode" .. vim.inspect(ns))
local cmd = [[setl makeprg=go\ test\ ]] .. tag .. [[-v\ -run\ ^]] .. ns.name .. [[\ ]] .. fpath
local cmd = [[setl makeprg=go\ test\ ]] .. get_build_tags(args) .. [[-v\ -run\ ^]] .. ns.name .. [[\ ]] .. fpath
.. [[ | lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
@ -28,13 +40,10 @@ M.test_file = function(args)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
local tag = ''
utils.log(args)
if args ~= nil then
tag = [[-tags\ ]] .. args .. [[\ ]]
end
local fpath = vim.fn.expand("%:p:h") .. '/..'
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
local cmd = [[setl makeprg=go\ test\ ]] .. tag .. [[-v\ -run\ ]] .. fpath
local cmd = [[setl makeprg=go\ test\ ]] .. get_build_tags(args) .. [[-v\ -run\ ]] .. fpath
.. [[| lua require"go.asyncmake".make()]]
utils.log("test cmd", cmd)
vim.cmd(cmd)

Loading…
Cancel
Save