diff --git a/lua/go/coverage.lua b/lua/go/coverage.lua index df86e40..1968cac 100644 --- a/lua/go/coverage.lua +++ b/lua/go/coverage.lua @@ -13,9 +13,6 @@ M.sign_map = { covered = 'goCoverageCovered', uncover = 'goCoverageUncovered', p local ns = 'gocoverage_ns' -local sign_covered = M.sign_map.covered -local sign_uncover = M.sign_map.uncover -local sign_partial = M.sign_map.partial local function sign_get(bufnr, name) if sign_define_cache[bufnr] == nil then @@ -110,7 +107,7 @@ function M.add(bufnr, signs) end end - -- log("placing", to_place) + log("placing", #to_place) vfn.sign_placelist(to_place) return to_place -- for testing end diff --git a/lua/go/format.lua b/lua/go/format.lua index 359f055..965ca07 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -4,7 +4,6 @@ local api = vim.api local utils = require('go.utils') local log = utils.log local max_len = _GO_NVIM_CFG.max_line_len or 120 -local goimport = _GO_NVIM_CFG.goimport or 'goimports' local gofmt = _GO_NVIM_CFG.gofmt or 'gofumpt' local vfn = vim.fn local install = require('go.install').install @@ -28,7 +27,7 @@ end local run = function(fmtargs, bufnr, cmd) bufnr = bufnr or 0 log(fmtargs, bufnr, cmd) - if _GO_NVIM_CFG.gofmt == 'gopls' then + if cmd == 'gopls' then if not vim.api.nvim_buf_is_loaded(bufnr) then vfn.bufload(bufnr) end @@ -36,12 +35,12 @@ local run = function(fmtargs, bufnr, cmd) if vim.o.mod == true then vim.cmd('write') end - vim.lsp.buf.format({ + -- log gopls format + return vim.lsp.buf.format({ async = _GO_NVIM_CFG.lsp_fmt_async, bufnr = bufnr, name = 'gopls', }) - return end local args = vim.deepcopy(fmtargs) @@ -80,7 +79,9 @@ local run = function(fmtargs, bufnr, cmd) end, on_stderr = function(_, data, _) data = utils.handle_job_data(data) - log(vim.inspect(data) .. 'from stderr') + if data then + log(vim.inspect(data) .. ' from stderr') + end end, on_exit = function(_, data, _) -- id, data, event -- log(vim.inspect(data) .. "exit") @@ -160,7 +161,10 @@ M.org_imports = function(wait_ms) end M.goimport = function(...) + + local goimport = _GO_NVIM_CFG.goimport or 'goimports' local args = { ... } + log(args, goimport) if _GO_NVIM_CFG.goimport == 'gopls' then if vfn.empty(args) == 1 then return M.org_imports(1000) diff --git a/lua/tests/go_coverage_spec.lua b/lua/tests/go_coverage_spec.lua index b41b53a..297dada 100644 --- a/lua/tests/go_coverage_spec.lua +++ b/lua/tests/go_coverage_spec.lua @@ -54,13 +54,13 @@ describe("should read coveragefile", function() local coverage = { { - cnt = 1, + covered = 1, file = "github.com/go.nvim/branch.go", filename = "branch.go", num = 1, range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}} }, { - cnt = 1, + covered = 1, file = "github.com/go.nvim/branch.go", filename = "branch.go", num = 1, @@ -69,7 +69,7 @@ describe("should read coveragefile", function() } local result = cover.add(1, coverage) - -- print(vim.inspect(result)) + print(vim.inspect(result)) local sign = { buffer = 1, group = 'gocoverage_ns', diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index d936244..bd8e281 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -47,6 +47,8 @@ describe('should run gofmt', function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/hello_golden.go'), '\n') local cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) + + vim.cmd([[packadd go.nvim]]) local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) print('buf read: ' .. vim.inspect(l)) @@ -66,7 +68,7 @@ describe('should run gofmt', function() cmd = 'bd! ' .. name vim.cmd(cmd) end) - it('should run import from file', function() + it('should run import from file with goimports', function() local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports.go' -- %:p:h ? %:p local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports_golden.go'), '\n') local name = vim.fn.tempname() .. '.go' @@ -75,10 +77,13 @@ describe('should run gofmt', function() vim.fn.writefile(lines, name) local cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) + + vim.cmd([[packadd go.nvim]]) require('go').setup({ goimport = 'goimports' }) + _GO_NVIM_CFG.goimport = 'goimports' vim.cmd([[cd %:p:h]]) require('go.format').goimport() - print('workspaces:', vim.inspect(vim.lsp.buf.list_workspace_folders())) + -- print('workspaces:', vim.inspect(vim.lsp.buf.list_workspace_folders())) vim.wait(500, function() end) local fmt = vim.fn.join(vim.fn.readfile(name), '\n') eq(expected, fmt) @@ -138,14 +143,14 @@ describe('should run gofmt', function() local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports3.go' -- %:p:h ? %:p local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports3_golden.go'), '\n') - _GO_NVIM_CFG.goimport = 'gopls' - local cmd = " silent exe 'e " .. path .. "'" vim.cmd(cmd) vim.cmd([[cd %:p:h]]) vim.cmd([[packadd go.nvim]]) require('go').setup({ goimport = 'gopls', lsp_cfg = true }) + + _GO_NVIM_CFG.goimport = 'gopls' vim.wait(2000, function() end) require('go.format').goimport() diff --git a/lua/tests/go_setup_spec.lua b/lua/tests/go_setup_spec.lua index 756cd59..f297647 100644 --- a/lua/tests/go_setup_spec.lua +++ b/lua/tests/go_setup_spec.lua @@ -33,20 +33,22 @@ describe('should run func make', function() }, }, } + + vim.wait(500, function() end) local gosetup = require('go.lsp').config() -- print(vim.inspect(gosetup)) eq(gosetup.settings.gopls.analyses, { - ST1003 = false, - fieldalignment = true, - fillreturns = true, - nilness = true, - nonewvars = true, - shadow = true, - undeclaredname = true, - unreachable = true, - unusedparams = false, - unusedwrite = true, - useany = true - }) + ST1003 = false, + fieldalignment = true, + fillreturns = true, + nilness = true, + nonewvars = true, + shadow = true, + undeclaredname = true, + unreachable = true, + unusedparams = false, + unusedwrite = true, + useany = true, + }) end) end)