efm format for quickfix; golangci-lint efm setup

pull/59/head
ray-x 3 years ago
parent 8712f31898
commit 6e87d834a4

@ -10,6 +10,7 @@ function M.make(...)
local indent = "%\\%( %\\)"
if not makeprg then
log('makeprog not setup')
return
end
@ -34,6 +35,10 @@ function M.make(...)
vim.api.nvim_buf_set_option(bufnr, "makeprg", makeprg)
end
if makeprg:find('test') then
log('go test')
end
local arg = " "
for _, v in pairs(args or {}) do
arg = arg .. " " .. v
@ -48,14 +53,18 @@ function M.make(...)
-- vim.cmd([[make %:r]])
local cmd = vim.fn.expandcmd(makeprg)
log(cmd)
local function on_event(job_id, data, event)
if event == "stdout" or event == "stderr" then
if data then
log('stdout', data)
vim.list_extend(lines, data)
end
end
if event == "exit" then
log(data)
vim.fn.setqflist({}, " ", {
title = cmd,
lines = lines,

@ -8,82 +8,84 @@ local function get_build_tags(args)
local space = [[\ ]]
if _GO_NVIM_CFG.run_in_floaterm then
space = ' '
space = " "
end
if _GO_NVIM_CFG.build_tags ~= "" then
tags = tags .. space .. _GO_NVIM_CFG.build_tags
end
for i, value in pairs(args) do
if value:find('-tags') then
if tags == '-tags' then
if value:find("-tags") then
if tags == "-tags" then
tags = value
else
tags = tags .. ',' .. value:sub(#'-tags=' + 1)
tags = tags .. "," .. value:sub(#"-tags=" + 1)
end
table.remove(args, i)
break
end
end
if tags == '-tags' then
tags = ''
if tags == "-tags" then
tags = ""
return tags, args
else
return space .. tags .. space, args
end
return space .. tags .. space, 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
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 tags, args2 = get_build_tags(args)
log(tags, args2)
if tags ~= "" then
tags = tags .. [[\ ]]
end
local argsstr = ""
if _GO_NVIM_CFG.run_in_floaterm then
argsstr = table.concat(args2 or {}, " ")
if argsstr == "" then
argsstr = '.' .. utils.sep() .. '...'
argsstr = "." .. utils.sep() .. "..."
end
local cmd = test_runner .. [[ test ]] .. tags .. [[ -v ]] .. argsstr
cmd = cmd .. tags .. [[ -v ]] .. argsstr
if path ~= '' then
if path ~= "" then
cmd = cmd .. [[ ]] .. path
end
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
local term = require("go.term").run
term({ cmd = cmd, autoclose = false })
return
end
argsstr = table.concat(args2 or {}, [[\ ]])
if argsstr == "" then
argsstr = '.' .. utils.sep() .. '...'
argsstr = "." .. utils.sep() .. "..." .. [[\ ]]
end
path = path or argsstr
local cmd = [[setl makeprg=go\ test\ ]] .. tags .. [[\ -v\ ]] .. argsstr .. [[\ ]]
.. path [[| lua require"go.asyncmake".make()]]
local cmd = [[setl makeprg=go\ test\ ]] .. tags .. path .. [[ | make]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end
M.test = function(...)
local args = {...}
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 = workfolder .. utils.sep() .. '...'
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
@ -92,12 +94,12 @@ M.test = function(...)
end
M.test_suit = function(...)
local args = {...}
local args = { ... }
log(args)
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
utils.log(args)
local fpath = workfolder .. utils.sep() .. '...'
local fpath = workfolder .. utils.sep() .. "..."
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
utils.log("fpath" .. fpath)
@ -105,29 +107,27 @@ M.test_suit = function(...)
end
M.test_package = function(...)
local args = {...}
local args = { ... }
log(args)
local repath = utils.rel_path() or ''
local repath = utils.rel_path() or ""
local fpath = repath .. utils.sep() .. '...'
local fpath = repath .. utils.sep() .. "..."
utils.log("fpath" .. fpath)
utils.log("fpath" .. fpath)
args[#args + 1] = fpath
run_test(fpath, args)
end
M.test_fun = function(...)
local args = {...}
local args = { ... }
log(args)
-- for i, v in ipairs(args) do
-- table.insert(setup, v)
-- end
local fpath = vim.fn.expand('%:p:h')
local fpath = vim.fn.expand("%:p:h")
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row, col = row, col + 1
local ns = require("go.ts.go").get_func_method_node_at_pos(row, col)
@ -139,22 +139,20 @@ M.test_fun = function(...)
local argsstr = ""
utils.log("parnode" .. vim.inspect(ns))
local test_runner = 'go'
if _GO_NVIM_CFG.test_runner ~= 'go' then
local test_runner = "go"
if _GO_NVIM_CFG.test_runner ~= "go" then
test_runner = _GO_NVIM_CFG.test_runner
if test_runner == 'ginkgo' then
if test_runner == "ginkgo" then
ginkgo.test_fun(...)
end
require("go.install").install(test_runner)
end
local bench = ''
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
@ -165,7 +163,7 @@ M.test_fun = function(...)
cmd = cmd .. [[-v -run ^]] .. ns.name
if bench ~= '' then
if bench ~= "" then
cmd = cmd .. [[ ]] .. bench
end
if argsstr ~= "" then
@ -175,8 +173,8 @@ M.test_fun = function(...)
cmd = cmd .. [[ ]] .. fpath
utils.log(cmd)
local term = require('go.term').run
term({cmd = cmd, autoclose = false})
local term = require("go.term").run
term({ cmd = cmd, autoclose = false })
return
end
@ -194,7 +192,7 @@ M.test_fun = function(...)
cmd = cmd .. [[-v\ -run\ ^]] .. ns.name
if bench ~= '' then
if bench ~= "" then
cmd = cmd .. [[\ ]] .. bench
end
if argsstr ~= "" then
@ -209,29 +207,29 @@ M.test_fun = function(...)
end
M.test_file = function(...)
local args = {...}
local args = { ... }
log(args)
-- require sed
-- local testcases = [[sed -n 's/func.*\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\\|/g']]
utils.log(args)
local cmd = [[cat ]] .. vim.fn.expand('%:p') .. [[| sed -n 's/func.*\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\\|/g']]
local cmd = [[cat ]] .. vim.fn.expand("%:p") .. [[| 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(tests)
if tests == nil or tests == {} then
print('no test found fallback to package test')
print("no test found fallback to package test")
M.test_package(...)
end
local tags, args2 = get_build_tags(args)
local argsstr = ""
local test_runner = 'go'
if _GO_NVIM_CFG.test_runner ~= 'go' then
local test_runner = "go"
if _GO_NVIM_CFG.test_runner ~= "go" then
test_runner = _GO_NVIM_CFG.test_runner
if test_runner == 'ginkgo' then
if test_runner == "ginkgo" then
ginkgo.test_fun(...)
end
require("go.install").install(test_runner)
@ -243,16 +241,48 @@ M.test_file = function(...)
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})
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()]]
local indent = "%\\%( %\\)"
local efm = [[%-G=== RUN %.%#]]
efm = efm .. ",%-G" .. indent .. "%#--- PASS: %.%#"
efm = efm .. ",%G--- FAIL: %\\%(Example%\\)%\\@=%m (%.%#)"
efm = efm .. ",%G" .. indent .. "%#--- FAIL: %m (%.%#)"
efm = efm .. ",%A" .. indent .. "%\\+%[%^:]%\\+: %f:%l: %m"
efm = efm .. ",%A" .. indent .. "%\\+%[%^:]%\\+: %f:%l: "
efm = efm .. ",%+Gpanic: test timed out after %.%\\+"
efm = efm .. ",%+Afatal error: %.%# [recovered]"
efm = efm .. ",%+Afatal error: %.%#"
efm = efm .. ",%+Apanic: %.%#"
-- exit
efm = efm .. ",%-Cexit status %[0-9]%\\+"
efm = efm .. ",exit status %[0-9]%\\+"
-- failed lines
efm = efm .. ",%-CFAIL%\\t%.%#"
-- compiling error
efm = efm .. ",%A%f:%l:%c: %m"
efm = efm .. ",%A%f:%l: %m"
efm = efm .. "%-C%.%#"
efm = efm .. ",%-G%.%#"
vim.cmd([[setl efm=]] .. efm)
cmd = [[setl makeprg=go\ test\ ]]
.. tags
.. [[-v\ -run\ ]]
.. tests
.. [[\ ]]
.. argsstr
.. [[\ ]]
.. relpath
.. [[| make]]
utils.log("test cmd", cmd)
vim.cmd(cmd)
end

@ -62,12 +62,14 @@ local function go_install(pkg)
})
end
local function install(bin)
local function install(bin, verbose)
if not is_installed(bin) then
print("installing " .. bin)
go_install(bin)
else
if verbose then
print(bin .. " already install, use GoUpdateBinary to update it")
end
end
end

Loading…
Cancel
Save