allow show coverage summary with 'go tool cover -func' in qf

pull/140/head
ray-x 2 years ago
parent 7045635404
commit fb4f37a328

@ -183,7 +183,7 @@ end
M.read_cov = function(covfn)
if vfn.filereadable(covfn) == 0 then
vim.notify(string.format("cov file not exist: %s", covfn), vim.lsp.log_levels.WARN)
vim.notify(string.format("cov file not exist: %s please run cover test first", covfn), vim.lsp.log_levels.WARN)
return
end
local cov = vfn.readfile(covfn)
@ -215,6 +215,50 @@ M.read_cov = function(covfn)
return coverage
end
M.show = function()
local setup = { "go", "tool", "cover", "-func=cover.cov" }
local result = {}
vfn.jobstart(setup, {
on_stdout = function(_, data, _)
data = utils.handle_job_data(data)
if not data then
return
end
for _, val in ipairs(data) do
-- first strip the filename
local l = vim.fn.split(val, ":")
local fname = l[1]
if vim.fn.filereadable(fname) == 0 then
local parts = vim.fn.split(fname, utils.sep())
for _ = 1, #parts do
table.remove(parts, 1)
fname = vim.fn.join(parts, utils.sep())
log("fname", fname)
if vim.fn.filereadable(fname) == 1 then
l[1] = fname
local d = vim.fn.join(l, ":")
log("putback ", d)
val = d
end
end
end
table.insert(result, val)
end
end,
on_exit = function(_, data, _)
if data ~= 0 then
vim.notify("no coverage data", vim.lsp.log_levels.WARN)
return
end
vim.fn.setqflist({}, " ", {
title = "go coverage",
lines = result,
})
vim.cmd("copen")
end,
})
end
M.run = function(...)
local get_build_tags = require("go.gotest").get_build_tags
-- local cov = vfn.tempname()
@ -264,7 +308,7 @@ M.run = function(...)
log(args2)
cmd = vim.list_extend(cmd, args2)
else
argsstr = "." .. utils.sep() .. "..."
local argsstr = "." .. utils.sep() .. "..."
table.insert(cmd, argsstr)
end
@ -320,7 +364,7 @@ M.run = function(...)
efm = vim.o.efm .. [[,]] .. require("go.gotest").efm(),
})
api.nvim_command("doautocmd QuickFixCmdPost")
vfn.delete(cov)
-- vfn.delete(cov) -- maybe keep the file for other commands
end,
})
end

@ -71,7 +71,7 @@ local run = function(fmtargs, bufnr, cmd)
end,
on_exit = function(_, data, _) -- id, data, event
-- log(vim.inspect(data) .. "exit")
if data.code ~= 0 then
if data ~= 0 then
return vim.notify("golines failed " .. tostring(data), vim.lsp.log_levels.ERROR)
end
old_lines = nil

Loading…
Cancel
Save