flags to load coverage file

pull/140/head
ray-x 2 years ago
parent b22f8c7760
commit b3c6bde824

@ -220,6 +220,8 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i
| GoGet {package_url} | go get package_url and restart gopls. Note1 |
| GoVet | go vet |
| GoCoverage | go test -coverprofile |
| GoCoverage -f coverage_file_name | load coverage file |
| GoCoverage {flags} | -t : toggle, -r: remove signs, -R remove sings from all files |
| GoTermClose | `closes the floating term` |
Note1: if package_url not provided, will check current line is a valid package url or not, if it is valid, will

@ -150,9 +150,11 @@ COMMANDS *go-nvim-commands*
[flags] are passed to the `go test` command; there are two special
flags:
-t coveragefile load coverage data from coveragefile
remove Remove all existing highlighting.
toggle Toggle display of highlighting.
-r Remove existing highlighting in current buffer.
-R Remove all existing highlighting.
-t Toggle display of highlighting.
*hl-goCoverageCovered* *hl-goCoverageUncover*

@ -224,6 +224,26 @@ M.run = function(...)
local args = { ... }
log(args)
local load = select(1, ...)
if load == "-f" then
local covfn = select(2, ...)
if covfn == nil then
vim.notify("no cov file specified", vim.lsp.log_levels.WARN)
return
end
return M.read_cov(covfn)
end
if load == "-t" then
return M.toggle()
end
if load == "-r" then
return M.remove()
end
if load == "-R" then
return M.remove_all()
end
local test_runner = "go"
if _GO_NVIM_CFG.test_runner ~= "go" then
test_runner = _GO_NVIM_CFG.test_runner
@ -266,7 +286,7 @@ M.run = function(...)
vfn.jobstart(cmd, {
on_stdout = function(jobid, data, event)
log("go coverage " .. vim.inspect(data), jobid, event)
log("go coverage " .. vim.inspect(data), jobid, event)
vim.list_extend(lines, data)
end,
on_stderr = function(job_id, data, event)

@ -10,6 +10,7 @@ local vfn = vim.fn
local long_opts = {
verbose = "v",
compile = "c",
coverage = "C",
tags = "t",
bench = "b",
select = "s",
@ -17,7 +18,7 @@ local long_opts = {
}
local sep = require("go.utils").sep()
local short_opts = "vct:bsF"
local short_opts = "vcC:t:bsF"
local bench_opts = { "-benchmem", "-cpuprofile", "profile.out" }
M.efm = function()
@ -130,6 +131,11 @@ local function run_test(path, args)
if not empty(tags) then
cmd = vim.list_extend(cmd, {tags})
end
if optarg["C"] then
table.insert(cmd, "-coverprofile=" .. optarg["C"])
end
if not empty(reminder) then
cmd = vim.list_extend(cmd, reminder)
end
@ -175,6 +181,7 @@ M.test = function(...)
local test_opts = {
verbose = "v",
compile = "c",
coverage = "C",
tags = "t",
bench = "b",
floaterm = "F",
@ -183,7 +190,7 @@ M.test = function(...)
package = "p",
}
local test_short_opts = "vct:bsfnpF"
local test_short_opts = "vcC:t:bsfnpF"
local optarg, _, reminder = getopt.get_opts(args, test_short_opts, test_opts)
vfn.setqflist({})

Loading…
Cancel
Save