From c0771b93c89e521dea9330028e73d0e70efbd10f Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:21:41 +1000 Subject: [PATCH 01/22] test workflow --- lua/go/format.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index 90325d3..a6cf28c 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -9,7 +9,7 @@ local gofmt = _GO_NVIM_CFG.gofmt ~= nil and _GO_NVIM_CFG.gofmt or "gofumpt" local gofmt_args = _GO_NVIM_CFG.gofmt_args and _GO_NVIM_CFG.gofmt_args or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. gofmt} -local goimport_args = _GO_NVIM_CFG.goimport_args and _GO_NVIM_CFG.goimport_args +local goimport_args = _GO_NVIM_CFG.goimport_args or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. goimport} local run = function(args, from_buffer, cmd) From d9e0a4be9fc0eee72576de1e3420ced74d75f5b6 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:34:57 +1000 Subject: [PATCH 02/22] workflow fix --- lua/go/format.lua | 10 +++++----- lua/tests/go_fmt_spec.lua | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index a6cf28c..be467df 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -4,9 +4,9 @@ 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 ~= nil and _GO_NVIM_CFG.goimport or "gofumports" -local gofmt = _GO_NVIM_CFG.gofmt ~= nil and _GO_NVIM_CFG.gofmt or "gofumpt" -local gofmt_args = _GO_NVIM_CFG.gofmt_args and _GO_NVIM_CFG.gofmt_args +local goimport = _GO_NVIM_CFG.goimport or "gofumports" +local gofmt = _GO_NVIM_CFG.gofmt or "gofumpt" +local gofmt_args = _GO_NVIM_CFG.gofmt_args or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. gofmt} local goimport_args = _GO_NVIM_CFG.goimport_args @@ -115,8 +115,8 @@ M.goimport = function(...) if args and _GO_NVIM_CFG.goimport == 'goimports' then run(args, true, 'goimports') else - utils.copy_array(goimport_args, a) - run({}, true) + -- utils.copy_array(goimport_args, a) + run(goimport_args, true) end end diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index f3fb079..49a37c1 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -114,6 +114,7 @@ describe("should run gofmt", function() vim.wait(200, function() end) local fmt = vim.fn.join(vim.fn.readfile(path), "\n") + print(vim.inspect(fmt)) -- eq(expected, fmt) eq(1, 1) -- still not working cmd = "bd! " .. path From 8b3b744b5e34be82e6c2c4ad3eb60bf3a87896cb Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:42:22 +1000 Subject: [PATCH 03/22] gopls format --- lua/tests/go_fmt_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 49a37c1..3f2fe4d 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -97,13 +97,14 @@ describe("should run gofmt", function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/fmt/goimports2_golden.go"), "\n") - require("go").setup({goimport = "gopls", lsp_cfg = true}) _GO_NVIM_CFG.goimport = 'gopls' local lines = vim.fn.readfile(path) local cmd = " silent exe 'e " .. path .. "'" vim.cmd(cmd) + + require("go").setup({goimport = "gopls", lsp_cfg = true}) vim.wait(1000, function() end) From 766fd37327d538ef5987ed5e11ce9d65866e5b82 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:48:58 +1000 Subject: [PATCH 04/22] print errors --- lua/tests/go_fmt_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 3f2fe4d..0f69b8c 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -116,7 +116,7 @@ describe("should run gofmt", function() end) local fmt = vim.fn.join(vim.fn.readfile(path), "\n") print(vim.inspect(fmt)) - -- eq(expected, fmt) + eq(expected, fmt) eq(1, 1) -- still not working cmd = "bd! " .. path vim.cmd(cmd) From 81c92c536288137a7930dd76e556936944a37d21 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:53:44 +1000 Subject: [PATCH 05/22] merge master --- lua/tests/go_fmt_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 0f69b8c..db10cf9 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -104,6 +104,7 @@ describe("should run gofmt", function() local cmd = " silent exe 'e " .. path .. "'" vim.cmd(cmd) + vim.cmd([[packadd go.nvim]]) require("go").setup({goimport = "gopls", lsp_cfg = true}) vim.wait(1000, function() end) From 79563afa495875442b13c491b33ce4f6ddf1388d Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:57:20 +1000 Subject: [PATCH 06/22] go setup --- lua/tests/go_coverage_spec.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/tests/go_coverage_spec.lua b/lua/tests/go_coverage_spec.lua index a0bb93c..5583a4a 100644 --- a/lua/tests/go_coverage_spec.lua +++ b/lua/tests/go_coverage_spec.lua @@ -12,7 +12,11 @@ describe("should read coveragefile", function() print("test:" .. path) -- go.nvim may not auto loaded vim.cmd([[packadd go.nvim]]) - require('go').setup({trace = true, log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log"}) + require('go').setup({ + trace = true, + lsp_cfg = true, + log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log" + }) local cover = require("go.coverage") local result = cover.read_cov(path) @@ -33,6 +37,7 @@ describe("should read coveragefile", function() vim.cmd([[packadd go.nvim]]) require('go').setup({ trace = true, + lsp_cfg = true, log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log", gocoverage_sign = '|' }) From cf8ca142e12ad61ffdd5f384d8cc797c9e8cfcf9 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 20:59:20 +1000 Subject: [PATCH 07/22] clean up --- lua/tests/go_coverage_spec.lua | 106 --------------------------------- 1 file changed, 106 deletions(-) diff --git a/lua/tests/go_coverage_spec.lua b/lua/tests/go_coverage_spec.lua index 5583a4a..6cb5be3 100644 --- a/lua/tests/go_coverage_spec.lua +++ b/lua/tests/go_coverage_spec.lua @@ -74,110 +74,4 @@ describe("should read coveragefile", function() eq(result[1], sign) -- eq(result[n][1], "github.com/go.nvim/branch.go") end) - - -- it("should run fmt sending from buffer", function() - -- local name = vim.fn.tempname() .. ".go" - -- print("tmp:" .. name) - -- -- - -- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p - -- print("test:" .. path) - -- local lines = vim.fn.readfile(path) - -- vim.fn.writefile(lines, name) - -- 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) - -- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) - -- print("buf read: " .. vim.inspect(l)) - -- - -- vim.bo.filetype = "go" - -- - -- print("exp:" .. vim.inspect(expected)) - -- print("tmp" .. name) - -- - -- local gofmt = require("go.format") - -- gofmt.gofmt(true) - -- -- enable the channel response - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- print("fmt" .. fmt) - -- vim.fn.assert_equal(fmt, expected) - -- eq(expected, fmt) - -- local cmd = "bd! " .. name - -- vim.cmd(cmd) - -- end) - -- it("should run import from file", 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" - -- print(name) - -- local lines = vim.fn.readfile(path) - -- vim.fn.writefile(lines, name) - -- local cmd = " silent exe 'e " .. name .. "'" - -- vim.cmd(cmd) - -- - -- vim.cmd([[cd %:p:h]]) - -- require("go.format").goimport() - -- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- eq(expected, fmt) - -- cmd = "bd! " .. name - -- vim.cmd(cmd) - -- end) - -- it("should run import from file with gopls", function() - -- local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p - -- local expected = vim.fn.join(vim.fn.readfile(cur_dir - -- .. "/lua/tests/fixtures/fmt/goimports2_golden.go"), - -- "\n") - -- require("go").setup({goimport = "gopls", lsp_cfg = true}) - -- - -- _GO_NVIM_CFG.goimport = 'gopls' - -- - -- local lines = vim.fn.readfile(path) - -- local cmd = " silent exe 'e " .. path .. "'" - -- vim.cmd(cmd) - -- vim.wait(1000, function() - -- end) - -- - -- vim.cmd([[cd %:p:h]]) - -- require("go.format").goimport() - -- - -- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) - -- vim.wait(200, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(path), "\n") - -- -- eq(expected, fmt) - -- eq(1, 1) -- still not working - -- cmd = "bd! " .. path - -- vim.cmd(cmd) - -- end) - -- it("should run import from file buffer with gofumpts", function() - -- _GO_NVIM_CFG.goimport = 'gofumports' - -- 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" - -- print(name) - -- local lines = vim.fn.readfile(path) - -- local cmd = " silent exe 'e " .. name .. "'" - -- vim.fn.writefile(lines, name) - -- vim.cmd(cmd) - -- vim.cmd([[cd %:p:h]]) - -- print("code write to " .. name) - -- local gofmt = require("go.format") - -- gofmt.goimport(true) - -- - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- - -- print(fmt) - -- eq(expected, fmt) - -- end) end) From 82fc245d782e5817ba251ea576d8a6de4dc69113 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 21:00:28 +1000 Subject: [PATCH 08/22] comment out --- lua/tests/go_fmt_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index db10cf9..1839213 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -117,7 +117,7 @@ describe("should run gofmt", function() end) local fmt = vim.fn.join(vim.fn.readfile(path), "\n") print(vim.inspect(fmt)) - eq(expected, fmt) + -- eq(expected, fmt) eq(1, 1) -- still not working cmd = "bd! " .. path vim.cmd(cmd) From e4abbb80eac3b7dbaecbc0723f1f954c316cde95 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 21:02:01 +1000 Subject: [PATCH 09/22] format --- lua/tests/go_fmt_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 1839213..f783ad6 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -111,13 +111,14 @@ describe("should run gofmt", function() vim.cmd([[cd %:p:h]]) require("go.format").goimport() + vim.cmd([[w]]) print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) vim.wait(200, function() end) local fmt = vim.fn.join(vim.fn.readfile(path), "\n") print(vim.inspect(fmt)) - -- eq(expected, fmt) + eq(expected, fmt) eq(1, 1) -- still not working cmd = "bd! " .. path vim.cmd(cmd) From c6b391a3031b2b8f94ce2ac90b72f1e242004a30 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 21:03:45 +1000 Subject: [PATCH 10/22] format --- lua/tests/go_fmt_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index f783ad6..ecaa661 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -109,7 +109,7 @@ describe("should run gofmt", function() vim.wait(1000, function() end) - vim.cmd([[cd %:p:h]]) + -- vim.cmd([[cd %:p:h]]) require("go.format").goimport() vim.cmd([[w]]) From 85b587fada2ca5c1b03286b8b17340cf9806a05e Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 21:07:32 +1000 Subject: [PATCH 11/22] gopls setup --- lua/go/lsp.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/go/lsp.lua b/lua/go/lsp.lua index 7f8ae74..74726c6 100644 --- a/lua/go/lsp.lua +++ b/lua/go/lsp.lua @@ -120,6 +120,8 @@ function M.setup() if _GO_NVIM_CFG.gopls_cmd then gopls.cmd = _GO_NVIM_CFG.gopls_cmd + else + gopls.cmd = {'gopls'} end if _GO_NVIM_CFG.lsp_gofumpt then From 446f4e6b9445c01c24b78e4b989e9b2944d863eb Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 21:14:13 +1000 Subject: [PATCH 12/22] fix gofmt --- lua/tests/fixtures/fmt/goimports2_golden.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/tests/fixtures/fmt/goimports2_golden.go b/lua/tests/fixtures/fmt/goimports2_golden.go index 50e8d8d..7291b32 100644 --- a/lua/tests/fixtures/fmt/goimports2_golden.go +++ b/lua/tests/fixtures/fmt/goimports2_golden.go @@ -2,6 +2,6 @@ package main import "fmt" -func main() { +func foo() { fmt.Println("vim-go") } From af25e1e2e7476d436f2bc0c69e79d8fb23c0a8d4 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 2 Sep 2021 22:27:40 +1000 Subject: [PATCH 13/22] goimport cleanup --- lua/go/format.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index be467df..8c0e4f9 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -4,7 +4,7 @@ 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 "gofumports" +local goimport = _GO_NVIM_CFG.goimport or "goimports" local gofmt = _GO_NVIM_CFG.gofmt or "gofumpt" local gofmt_args = _GO_NVIM_CFG.gofmt_args or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. gofmt} @@ -113,9 +113,6 @@ M.goimport = function(...) require("go.install").install("golines") if args and _GO_NVIM_CFG.goimport == 'goimports' then - run(args, true, 'goimports') - else - -- utils.copy_array(goimport_args, a) run(goimport_args, true) end end From bdce678adf35e7429eb8ff3a15b8f7d4094723fd Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 01:11:09 +1000 Subject: [PATCH 14/22] sequences --- lua/tests/go_fmt_spec.lua | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index ecaa661..46cfa4f 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -92,6 +92,31 @@ describe("should run gofmt", function() cmd = "bd! " .. name vim.cmd(cmd) end) + it("should run import from file buffer with goimport", function() + _GO_NVIM_CFG.goimport = 'goimport' + 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" + print(name) + local lines = vim.fn.readfile(path) + local cmd = " silent exe 'e " .. name .. "'" + vim.fn.writefile(lines, name) + vim.cmd(cmd) + vim.cmd([[cd %:p:h]]) + print("code write to " .. name) + local gofmt = require("go.format") + gofmt.goimport(true) + + vim.wait(100, function() + end) + local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + + print(fmt) + eq(expected, fmt) + end) + it("should run import from file with gopls", function() local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p local expected = vim.fn.join(vim.fn.readfile(cur_dir @@ -100,7 +125,6 @@ describe("should run gofmt", function() _GO_NVIM_CFG.goimport = 'gopls' - local lines = vim.fn.readfile(path) local cmd = " silent exe 'e " .. path .. "'" vim.cmd(cmd) @@ -123,28 +147,4 @@ describe("should run gofmt", function() cmd = "bd! " .. path vim.cmd(cmd) end) - it("should run import from file buffer with gofumpts", function() - _GO_NVIM_CFG.goimport = 'gofumports' - 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" - print(name) - local lines = vim.fn.readfile(path) - local cmd = " silent exe 'e " .. name .. "'" - vim.fn.writefile(lines, name) - vim.cmd(cmd) - vim.cmd([[cd %:p:h]]) - print("code write to " .. name) - local gofmt = require("go.format") - gofmt.goimport(true) - - vim.wait(100, function() - end) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - - print(fmt) - eq(expected, fmt) - end) end) From 6cb17285ff2a0ad7a5e0101c901d112fefd43da1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 01:17:30 +1000 Subject: [PATCH 15/22] save --- lua/tests/go_fmt_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 46cfa4f..65bc7e7 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -111,6 +111,7 @@ describe("should run gofmt", function() vim.wait(100, function() end) + vim.cmd([[w]]) local fmt = vim.fn.join(vim.fn.readfile(name), "\n") print(fmt) From b517d7a6b9610d6d195526faaef8c31a84f09cc5 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:15:54 +1000 Subject: [PATCH 16/22] updates --- lua/go/format.lua | 8 ++- lua/tests/go_fmt_spec.lua | 133 +++++++++++++++++++------------------- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index 8c0e4f9..0900dbf 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -12,11 +12,13 @@ local gofmt_args = _GO_NVIM_CFG.gofmt_args local goimport_args = _GO_NVIM_CFG.goimport_args or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. goimport} -local run = function(args, from_buffer, cmd) - +local run = function(fmtargs, from_buffer, cmd) + local args = vim.deepcopy(fmtargs) if not from_buffer then table.insert(args, api.nvim_buf_get_name(0)) - print('formatting... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args)) + print('formatting buffer... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args)) + else + print('formatting... ' .. vim.inspect(args)) end local old_lines = api.nvim_buf_get_lines(0, 0, -1, true) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 65bc7e7..2bd706d 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -6,70 +6,70 @@ describe("should run gofmt", function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) status = require("plenary.reload").reload_module("go.nvim") - it("should run fmt", function() - local name = vim.fn.tempname() .. ".go" - print("tmp:" .. name) - -- - local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p - print("test:" .. path) - local lines = vim.fn.readfile(path) - vim.fn.writefile(lines, name) - 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) - local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) - print("buf read: " .. vim.inspect(l)) - - vim.bo.filetype = "go" - - print("exp:" .. vim.inspect(expected)) - print("tmp" .. name) - - local gofmt = require("go.format") - gofmt.gofmt() - -- enable the channel response - vim.wait(100, function() - end) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - print("fmt" .. fmt) - vim.fn.assert_equal(fmt, expected) - eq(expected, fmt) - local cmd = "bd! " .. name - vim.cmd(cmd) - end) - it("should run fmt sending from buffer", function() - local name = vim.fn.tempname() .. ".go" - print("tmp:" .. name) - -- - local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p - print("test:" .. path) - local lines = vim.fn.readfile(path) - vim.fn.writefile(lines, name) - 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) - local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) - print("buf read: " .. vim.inspect(l)) - - vim.bo.filetype = "go" - - print("exp:" .. vim.inspect(expected)) - print("tmp" .. name) - - local gofmt = require("go.format") - gofmt.gofmt(true) - -- enable the channel response - vim.wait(100, function() - end) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - print("fmt" .. fmt) - vim.fn.assert_equal(fmt, expected) - eq(expected, fmt) - local cmd = "bd! " .. name - vim.cmd(cmd) - end) + -- it("should run fmt", function() + -- local name = vim.fn.tempname() .. ".go" + -- print("tmp:" .. name) + -- -- + -- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p + -- print("test:" .. path) + -- local lines = vim.fn.readfile(path) + -- vim.fn.writefile(lines, name) + -- 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) + -- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) + -- print("buf read: " .. vim.inspect(l)) + -- + -- vim.bo.filetype = "go" + -- + -- print("exp:" .. vim.inspect(expected)) + -- print("tmp" .. name) + -- + -- local gofmt = require("go.format") + -- gofmt.gofmt() + -- -- enable the channel response + -- vim.wait(100, function() + -- end) + -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + -- print("fmt" .. fmt) + -- vim.fn.assert_equal(fmt, expected) + -- eq(expected, fmt) + -- local cmd = "bd! " .. name + -- vim.cmd(cmd) + -- end) + -- it("should run fmt sending from buffer", function() + -- local name = vim.fn.tempname() .. ".go" + -- print("tmp:" .. name) + -- -- + -- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p + -- print("test:" .. path) + -- local lines = vim.fn.readfile(path) + -- vim.fn.writefile(lines, name) + -- 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) + -- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) + -- print("buf read: " .. vim.inspect(l)) + -- + -- vim.bo.filetype = "go" + -- + -- print("exp:" .. vim.inspect(expected)) + -- print("tmp" .. name) + -- + -- local gofmt = require("go.format") + -- gofmt.gofmt(true) + -- -- enable the channel response + -- vim.wait(100, function() + -- end) + -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + -- print("fmt" .. fmt) + -- vim.fn.assert_equal(fmt, expected) + -- eq(expected, fmt) + -- local cmd = "bd! " .. name + -- vim.cmd(cmd) + -- end) it("should run import from file", function() local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p local expected = vim.fn.join(vim.fn.readfile(cur_dir @@ -81,7 +81,7 @@ describe("should run gofmt", function() vim.fn.writefile(lines, name) local cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) - + require("go").setup({goimport = "goimports"}) vim.cmd([[cd %:p:h]]) require("go.format").goimport() print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) @@ -93,7 +93,6 @@ describe("should run gofmt", function() vim.cmd(cmd) end) it("should run import from file buffer with goimport", function() - _GO_NVIM_CFG.goimport = 'goimport' 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"), @@ -106,6 +105,8 @@ describe("should run gofmt", function() vim.cmd(cmd) vim.cmd([[cd %:p:h]]) print("code write to " .. name) + + require("go").setup({goimport = "goimports"}) local gofmt = require("go.format") gofmt.goimport(true) From d6f0249023ebef81aa1cec7f064797970b3eab7b Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:21:31 +1000 Subject: [PATCH 17/22] format --- lua/go/format.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index 0900dbf..c3dc14b 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -105,17 +105,17 @@ M.org_imports = function(wait_ms) vim.lsp.buf.formatting() end -M.goimport = function(...) +M.goimport = function(buf) if _GO_NVIM_CFG.goimport == 'gopls' then M.org_imports(1000) return end - local args = {...} + buf = buf or false require("go.install").install(goimport) require("go.install").install("golines") - if args and _GO_NVIM_CFG.goimport == 'goimports' then - run(goimport_args, true) + if _GO_NVIM_CFG.goimport == 'goimports' then + run(goimport_args, buf) end end From da9cd35645ea79f7798a3b6fba1ff99c60fb31ae Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:25:54 +1000 Subject: [PATCH 18/22] gopls 2s --- lua/tests/go_fmt_spec.lua | 99 +++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 2bd706d..1bc5acc 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -70,54 +70,54 @@ describe("should run gofmt", function() -- local cmd = "bd! " .. name -- vim.cmd(cmd) -- end) - it("should run import from file", 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" - print(name) - local lines = vim.fn.readfile(path) - vim.fn.writefile(lines, name) - local cmd = " silent exe 'e " .. name .. "'" - vim.cmd(cmd) - require("go").setup({goimport = "goimports"}) - vim.cmd([[cd %:p:h]]) - require("go.format").goimport() - print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) - vim.wait(100, function() - end) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - eq(expected, fmt) - cmd = "bd! " .. name - vim.cmd(cmd) - end) - it("should run import from file buffer with goimport", 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" - print(name) - local lines = vim.fn.readfile(path) - local cmd = " silent exe 'e " .. name .. "'" - vim.fn.writefile(lines, name) - vim.cmd(cmd) - vim.cmd([[cd %:p:h]]) - print("code write to " .. name) - - require("go").setup({goimport = "goimports"}) - local gofmt = require("go.format") - gofmt.goimport(true) - - vim.wait(100, function() - end) - vim.cmd([[w]]) - local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - - print(fmt) - eq(expected, fmt) - end) + -- it("should run import from file", 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" + -- print(name) + -- local lines = vim.fn.readfile(path) + -- vim.fn.writefile(lines, name) + -- local cmd = " silent exe 'e " .. name .. "'" + -- vim.cmd(cmd) + -- require("go").setup({goimport = "goimports"}) + -- vim.cmd([[cd %:p:h]]) + -- require("go.format").goimport() + -- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) + -- vim.wait(100, function() + -- end) + -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + -- eq(expected, fmt) + -- cmd = "bd! " .. name + -- vim.cmd(cmd) + -- end) + -- it("should run import from file buffer with goimport", 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" + -- print(name) + -- local lines = vim.fn.readfile(path) + -- local cmd = " silent exe 'e " .. name .. "'" + -- vim.fn.writefile(lines, name) + -- vim.cmd(cmd) + -- vim.cmd([[cd %:p:h]]) + -- print("code write to " .. name) + -- + -- require("go").setup({goimport = "goimports"}) + -- local gofmt = require("go.format") + -- gofmt.goimport(true) + -- + -- vim.wait(100, function() + -- end) + -- vim.cmd([[w]]) + -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + -- + -- print(fmt) + -- eq(expected, fmt) + -- end) it("should run import from file with gopls", function() local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p @@ -132,12 +132,11 @@ describe("should run gofmt", function() vim.cmd([[packadd go.nvim]]) require("go").setup({goimport = "gopls", lsp_cfg = true}) - vim.wait(1000, function() + vim.wait(2000, function() end) -- vim.cmd([[cd %:p:h]]) require("go.format").goimport() - vim.cmd([[w]]) print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) vim.wait(200, function() From 00a740590445cd67aaec75262552bfdf68c0f6c6 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:33:34 +1000 Subject: [PATCH 19/22] save file --- lua/tests/go_fmt_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index 1bc5acc..d941e8d 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -130,17 +130,18 @@ describe("should run gofmt", function() 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}) vim.wait(2000, function() end) - -- vim.cmd([[cd %:p:h]]) require("go.format").goimport() print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) vim.wait(200, function() end) + vim.cmd([[w]]) local fmt = vim.fn.join(vim.fn.readfile(path), "\n") print(vim.inspect(fmt)) eq(expected, fmt) From c67b1c8912d88990ddb06dabcd28fa712b0bd9cc Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:35:54 +1000 Subject: [PATCH 20/22] revert changes --- lua/tests/go_fmt_spec.lua | 224 +++++++++++++++++++------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index d941e8d..85ce67b 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -6,118 +6,118 @@ describe("should run gofmt", function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) status = require("plenary.reload").reload_module("go.nvim") - -- it("should run fmt", function() - -- local name = vim.fn.tempname() .. ".go" - -- print("tmp:" .. name) - -- -- - -- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p - -- print("test:" .. path) - -- local lines = vim.fn.readfile(path) - -- vim.fn.writefile(lines, name) - -- 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) - -- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) - -- print("buf read: " .. vim.inspect(l)) - -- - -- vim.bo.filetype = "go" - -- - -- print("exp:" .. vim.inspect(expected)) - -- print("tmp" .. name) - -- - -- local gofmt = require("go.format") - -- gofmt.gofmt() - -- -- enable the channel response - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- print("fmt" .. fmt) - -- vim.fn.assert_equal(fmt, expected) - -- eq(expected, fmt) - -- local cmd = "bd! " .. name - -- vim.cmd(cmd) - -- end) - -- it("should run fmt sending from buffer", function() - -- local name = vim.fn.tempname() .. ".go" - -- print("tmp:" .. name) - -- -- - -- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p - -- print("test:" .. path) - -- local lines = vim.fn.readfile(path) - -- vim.fn.writefile(lines, name) - -- 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) - -- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) - -- print("buf read: " .. vim.inspect(l)) - -- - -- vim.bo.filetype = "go" - -- - -- print("exp:" .. vim.inspect(expected)) - -- print("tmp" .. name) - -- - -- local gofmt = require("go.format") - -- gofmt.gofmt(true) - -- -- enable the channel response - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- print("fmt" .. fmt) - -- vim.fn.assert_equal(fmt, expected) - -- eq(expected, fmt) - -- local cmd = "bd! " .. name - -- vim.cmd(cmd) - -- end) - -- it("should run import from file", 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" - -- print(name) - -- local lines = vim.fn.readfile(path) - -- vim.fn.writefile(lines, name) - -- local cmd = " silent exe 'e " .. name .. "'" - -- vim.cmd(cmd) - -- require("go").setup({goimport = "goimports"}) - -- vim.cmd([[cd %:p:h]]) - -- require("go.format").goimport() - -- print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) - -- vim.wait(100, function() - -- end) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- eq(expected, fmt) - -- cmd = "bd! " .. name - -- vim.cmd(cmd) - -- end) - -- it("should run import from file buffer with goimport", 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" - -- print(name) - -- local lines = vim.fn.readfile(path) - -- local cmd = " silent exe 'e " .. name .. "'" - -- vim.fn.writefile(lines, name) - -- vim.cmd(cmd) - -- vim.cmd([[cd %:p:h]]) - -- print("code write to " .. name) - -- - -- require("go").setup({goimport = "goimports"}) - -- local gofmt = require("go.format") - -- gofmt.goimport(true) - -- - -- vim.wait(100, function() - -- end) - -- vim.cmd([[w]]) - -- local fmt = vim.fn.join(vim.fn.readfile(name), "\n") - -- - -- print(fmt) - -- eq(expected, fmt) - -- end) + it("should run fmt", function() + local name = vim.fn.tempname() .. ".go" + print("tmp:" .. name) + -- + local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p + print("test:" .. path) + local lines = vim.fn.readfile(path) + vim.fn.writefile(lines, name) + 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) + local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) + print("buf read: " .. vim.inspect(l)) + + vim.bo.filetype = "go" + + print("exp:" .. vim.inspect(expected)) + print("tmp" .. name) + + local gofmt = require("go.format") + gofmt.gofmt() + -- enable the channel response + vim.wait(100, function() + end) + local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + print("fmt" .. fmt) + vim.fn.assert_equal(fmt, expected) + eq(expected, fmt) + local cmd = "bd! " .. name + vim.cmd(cmd) + end) + it("should run fmt sending from buffer", function() + local name = vim.fn.tempname() .. ".go" + print("tmp:" .. name) + -- + local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p + print("test:" .. path) + local lines = vim.fn.readfile(path) + vim.fn.writefile(lines, name) + 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) + local l = vim.api.nvim_buf_get_lines(0, 0, -1, true) + print("buf read: " .. vim.inspect(l)) + + vim.bo.filetype = "go" + + print("exp:" .. vim.inspect(expected)) + print("tmp" .. name) + + local gofmt = require("go.format") + gofmt.gofmt(true) + -- enable the channel response + vim.wait(100, function() + end) + local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + print("fmt" .. fmt) + vim.fn.assert_equal(fmt, expected) + eq(expected, fmt) + local cmd = "bd! " .. name + vim.cmd(cmd) + end) + it("should run import from file", 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" + print(name) + local lines = vim.fn.readfile(path) + vim.fn.writefile(lines, name) + local cmd = " silent exe 'e " .. name .. "'" + vim.cmd(cmd) + require("go").setup({goimport = "goimports"}) + vim.cmd([[cd %:p:h]]) + require("go.format").goimport() + print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) + vim.wait(100, function() + end) + local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + eq(expected, fmt) + cmd = "bd! " .. name + vim.cmd(cmd) + end) + it("should run import from file buffer with goimport", 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" + print(name) + local lines = vim.fn.readfile(path) + local cmd = " silent exe 'e " .. name .. "'" + vim.fn.writefile(lines, name) + vim.cmd(cmd) + vim.cmd([[cd %:p:h]]) + print("code write to " .. name) + + require("go").setup({goimport = "goimports"}) + local gofmt = require("go.format") + gofmt.goimport(true) + + vim.wait(100, function() + end) + vim.cmd([[w]]) + local fmt = vim.fn.join(vim.fn.readfile(name), "\n") + + print(fmt) + eq(expected, fmt) + end) it("should run import from file with gopls", function() local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p From 5c5b102b93f99034aeee8eb727f686c967769efa Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 02:59:45 +1000 Subject: [PATCH 21/22] arguments --- lua/go/format.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index c3dc14b..6813b94 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -105,18 +105,25 @@ M.org_imports = function(wait_ms) vim.lsp.buf.formatting() end -M.goimport = function(buf) +M.goimport = function(...) if _GO_NVIM_CFG.goimport == 'gopls' then M.org_imports(1000) return end - buf = buf or false + local args = {...} + local a1 = select(1, args) + local buf = true + if type(a1) == "boolean" then + buf = a1 + table.remove(args, 1) + end require("go.install").install(goimport) require("go.install").install("golines") - - if _GO_NVIM_CFG.goimport == 'goimports' then - run(goimport_args, buf) + local a = vim.deepcopy(goimport_args) + if #args > 0 and _GO_NVIM_CFG.goimport == 'goimports' then -- dont use golines + return run(args, buf, 'goimports') end + run(goimport_args, buf) end return M From 8ea0ff1d3aa712296af192e217408c2133eca572 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 3 Sep 2021 03:14:04 +1000 Subject: [PATCH 22/22] commit --- lua/go/format.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/go/format.lua b/lua/go/format.lua index 6813b94..6c3ed09 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -27,7 +27,7 @@ local run = function(fmtargs, from_buffer, cmd) else table.insert(args, 1, "golines") end - log(args) + log("fmt cmd:", args) local j = vim.fn.jobstart(args, { on_stdout = function(job_id, data, event) @@ -113,7 +113,7 @@ M.goimport = function(...) local args = {...} local a1 = select(1, args) local buf = true - if type(a1) == "boolean" then + if #args > 0 and type(args[1]) == "boolean" then buf = a1 table.remove(args, 1) end