bug fix for github workflow

pull/50/head
ray-x 3 years ago
parent 4eeafad97e
commit 0bc7abace6

@ -14,6 +14,10 @@ jobs:
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
manager: sudo snap
packages: go
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/v0.6.0/nvim-linux64.tar.gz
manager: sudo snap
packages: go
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/v0.5.1/nvim-linux64.tar.gz
manager: sudo snap

@ -6,11 +6,13 @@ 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 gofmt_args = _GO_NVIM_CFG.gofmt_args
or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. gofmt}
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
or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. goimport}
local goimport_args = _GO_NVIM_CFG.goimport_args or {
"--max-len=" .. tostring(max_len), "--base-formatter=" .. goimport
}
local run = function(fmtargs, from_buffer, cmd)
local args = vim.deepcopy(fmtargs)
@ -47,7 +49,7 @@ local run = function(fmtargs, from_buffer, cmd)
end,
on_stderr = function(job_id, data, event)
log(vim.inspect(data) .. "stderr")
log(vim.inspect(data) .. "from stderr")
end,
on_exit = function(id, data, event)
-- log(vim.inspect(data) .. "exit")

@ -12,6 +12,7 @@ local tags = {}
local opts = {
"-add-tags", "-add-options", "-remove-tags", "-remove-options", "-clear-tags", "-clear-options"
}
local gomodify = "gomodifytags"
local transform = _GO_NVIM_CFG.tag_transfer
tags.modify = function(...)
@ -58,12 +59,14 @@ tags.modify = function(...)
local tagged = vim.fn.json_decode(data)
-- print(vim.inspect(tagged))
-- print(tagged["start"], tagged["end"], tagged.lines)
if tagged.errors ~= nil or tagged.lines == nil or tagged["start"] == nil or tagged["start"]
== 0 then
if tagged.errors ~= nil or tagged.lines == nil or tagged["start"] == nil or tagged["start"] == 0 then
print("failed to set tags" .. vim.inspect(tagged))
end
vim.api.nvim_buf_set_lines(0, tagged["start"] - 1, tagged["start"] - 1 + #tagged.lines, false,
tagged.lines)
for index, value in ipairs(tagged.lines) do
tagged.lines[index] = utils.rtrim(value)
end
-- trim tail spaces?
vim.api.nvim_buf_set_lines(0, tagged["start"] - 1, tagged["start"] - 1 + #tagged.lines, false, tagged.lines)
vim.cmd("write")
print("struct updated ")
end

@ -123,7 +123,7 @@ util.log = function(...)
if log_path ~= nil and #log_path > 3 then
local f, err = io.open(log_path, "a+")
if err then
print("failed to open log")
print("failed to open log", log_path, err)
return
end
if not f then
@ -305,4 +305,12 @@ function util.rel_path()
return fpath
end
function util.rtrim(s)
local n = #s
while n > 0 and s:find("^%s", n) do
n = n - 1
end
return s:sub(1, n)
end
return util

@ -14,8 +14,7 @@ describe("should run gofmt", function()
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 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)
@ -29,7 +28,7 @@ describe("should run gofmt", function()
local gofmt = require("go.format")
gofmt.gofmt()
-- enable the channel response
vim.wait(100, function()
vim.wait(400, function()
end)
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
print("fmt" .. fmt)
@ -46,8 +45,7 @@ describe("should run gofmt", function()
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 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)
@ -72,9 +70,7 @@ describe("should run gofmt", function()
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 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)
@ -85,7 +81,7 @@ describe("should run gofmt", function()
vim.cmd([[cd %:p:h]])
require("go.format").goimport()
print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
vim.wait(100, function()
vim.wait(400, function()
end)
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
eq(expected, fmt)
@ -94,9 +90,7 @@ describe("should run gofmt", function()
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 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)
@ -110,7 +104,7 @@ describe("should run gofmt", function()
local gofmt = require("go.format")
gofmt.goimport(true)
vim.wait(100, function()
vim.wait(400, function()
end)
vim.cmd([[w]])
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
@ -121,9 +115,7 @@ describe("should run gofmt", function()
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")
local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/fmt/goimports2_golden.go"), "\n")
_GO_NVIM_CFG.goimport = 'gopls'
@ -139,7 +131,7 @@ describe("should run gofmt", function()
require("go.format").goimport()
print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
vim.wait(200, function()
vim.wait(400, function()
end)
vim.cmd([[w]])
local fmt = vim.fn.join(vim.fn.readfile(path), "\n")

@ -29,6 +29,7 @@ require("plenary/busted")
require("go").setup({
gofmt = 'gofumpt',
goimport = "goimports",
log_path = vim.fn.expand("$HOME") .. "/gonvim.log",
lsp_cfg = true,
})
EOF

Loading…
Cancel
Save