diff --git a/README.md b/README.md index d05d02c..096228c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/doc/go.txt b/doc/go.txt index eaa1429..c1bdade 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -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* diff --git a/lua/go/coverage.lua b/lua/go/coverage.lua index 78c0774..ecab413 100644 --- a/lua/go/coverage.lua +++ b/lua/go/coverage.lua @@ -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) diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index 8e5bf24..14a97bb 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -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({})