From 02fbdd126c1d688b31c71002d7180823dc3f112b Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 28 Dec 2022 10:31:23 +1100 Subject: [PATCH] =?UTF-8?q?issue=20#264=20coverage=20line=20num=20mismatch?= =?UTF-8?q?=20=F0=9F=8E=84=F0=9F=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + lua/go/coverage.lua | 24 ++++++++++++------------ lua/tests/fixtures/coverage/tag_test.go | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8d93780..2754408 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,7 @@ first run of `GoFmt` may fail. Recommended to run `GoInstallBinaries` to install | GoCoverage -p | go test -coverprofile (only tests package for current buffer) | | GoCoverage -f coverage_file_name | load coverage file | | GoCoverage {flags} | -t : toggle, -r: remove signs, -R remove sings from all files, -m show metrics| +| GoCoverage {flags} {go test flags} | e.g: GoCoverage -p -coverpkg 'yourpackagename' | | GoTermClose | `closes the floating term` | Note: diff --git a/lua/go/coverage.lua b/lua/go/coverage.lua index 844df45..68bb872 100644 --- a/lua/go/coverage.lua +++ b/lua/go/coverage.lua @@ -80,19 +80,19 @@ end function M.add(bufnr, signs) local to_place = {} for _, s in ipairs(signs or {}) do - local count = s.cnt - local stype = 'goCoverageCovered' - if count == 0 then - stype = 'goCoverageUncovered' + local covered = s.covered + local sign_group = 'goCoverageCovered' + if covered == 0 then + sign_group = 'goCoverageUncovered' end - M.define(bufnr, stype, { text = _GO_NVIM_CFG.gocoverage_sign, texthl = stype }) - for lnum = s.range.start.line, s.range['end'].line + 1 do - -- log(lnum, bufnr) --verbose + M.define(bufnr, sign_group, { text = _GO_NVIM_CFG.gocoverage_sign, texthl = sign_group }) + for lnum = s.range.start.line, s.range['end'].line do + log(lnum, covered, bufnr) --verbose to_place[#to_place + 1] = { id = lnum, group = ns, - name = stype, + name = sign_group, buffer = bufnr, lnum = lnum, priority = _GO_NVIM_CFG.sign_priority, @@ -180,7 +180,7 @@ local function parse_line(line) ['end'] = { line = tonumber(m[5]), character = tonumber(m[6]) }, }, num = tonumber(m[7]), - cnt = tonumber(m[8]), + covered = tonumber(m[8]), } end @@ -203,7 +203,7 @@ M.read_cov = function(covfn) local total_covered = 0 if vfn.filereadable(covfn) == 0 then - vim.notify(string.format('cov file not exist: %s please run cover test first', covfn), vim.lsp.log_levels.WARN) + vim.notify(string.format('cov file %s not exist please run cover test first', covfn), vim.lsp.log_levels.WARN) return end local cov = vfn.readfile(covfn) @@ -218,7 +218,7 @@ M.read_cov = function(covfn) end coverage[cl.filename].file_lines = (coverage[cl.filename].file_lines or 0) + cl.num file_lines = file_lines + cl.num - if cl.cnt > 0 then + if cl.covered > 0 then coverage[cl.filename].file_covered = (coverage[cl.filename].file_covered or 0) + cl.num total_covered = total_covered + cl.num end @@ -320,7 +320,7 @@ M.run = function(...) end arg = select(2, ...) end - if arg == '-t' and #args < 2 then -- if only -t provided + if arg == '-t' and #args < 2 then -- if only -t provided return M.toggle() end diff --git a/lua/tests/fixtures/coverage/tag_test.go b/lua/tests/fixtures/coverage/tag_test.go index d6c8cdf..575cfab 100644 --- a/lua/tests/fixtures/coverage/tag_test.go +++ b/lua/tests/fixtures/coverage/tag_test.go @@ -1,6 +1,6 @@ //+build integration,unit -package "testing" +package main func TestTag(t *testing.T) { t.Log("TestTag")